Search Results: 2705


How to get all children (ForeignKey based) from parent objects in a django template (e.g all comments for a blog post) ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    02 mai 2022    /    : 365

Example of how to get all children from parent objects in a django template: [TOC] ### Models.py file Let's consider the following case: a blog website in which a post can be created and commented as well: class Blog_Post(models.Model): content = models.TextField() date_created = models.DateTimeField(default=datetime.now) class Blog_Post_Comment(models.Model): blog_post = models.ForeignKey(Blog_Post, null=True, blank=True, default = None,on_delete=models.DO_NOTHING) ...

Image    /    Daidalos    /    CC BY-SA 4.0    /    08 avril 2022    /    : 0

Image    /    Daidalos    /    CC BY-SA 4.0    /    08 avril 2022    /    : 0

Image    /    Daidalos    /    CC BY-SA 4.0    /    08 avril 2022    /    : 0

How to append a new li to ul using javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    08 avril 2022    /    : 94

Examples of how to append a new li to ul using javascript: [TOC] ### Create a simple HTML page Let's consider the following html page: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> </head> <body> <ul id="mylist"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> <script> </script> </body> </html> The goal is to append 'item-4' to the ul with the id = "mylist" using javasc ...

Complete RoadMap: How to Crack Data Science Interview

Article    /    codebuster    /    Public Domain    /    07 avril 2022    /    : 51

### What is Data Science? Data science is a branch of computer science that deals with the mining or extraction of knowledge or valuable insights from the large-scale processing and analysis of raw data. The beauty lies in the limit of Data Science, which is boundless, as it can be applied to almost any area where there is data, and thus the core foundation of Data Science is laid down by various technologies like Automated Machine Learning, Artificial Intelligence, Big Data, Cloud Services, ...

How to fix "TypeError: Object of type datetime is not JSON serializable" in python ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    04 avril 2022    /    : 64

Example of how to fix the TypeError: Object of type datetime is not JSON serializable" in python: [TOC] Let's consider an example: ### Create a datetime object Reminder: to create a datetime object in python import datetime x = datetime.datetime.now() gives for example 2022-04-04 14:16:59.604425 which is a datetime object ### Create a json file Now if we try to create a json file using a dictionary with a datetime object inside: import json dict = {"me ...

Comment intégrer ("embed") une visualisation créé avec un notebook d'observable d3.js dans un site web ?

Article    /    Bazinga    /    CC BY-SA 4.0    /    22 mars 2022    /    : 59

Au début, j'étais un peu inquiet à l'idée d'utiliser d3 pour créer des outils d'analyse de données car je ne connait pas très bien le language javascript, mais l'investissement en temps en vaut vraiment la peine. Ainsi, après avoir créé une visualisation simple à l'aide du bloc-notes observable d3 (Data Driven Decisions), j'ai voulu tester comment l'intégrer dans une simple page HTML : [TOC] ### Option 1: intégrer une ou plusieurs cellules d'un d3 observable notebook Considérons le b ...

Comment supprimer une table dans une base de données avec le framework web django ?

Article    /    Bazinga    /    CC BY-SA 4.0    /    21 mars 2022    /    : 57

Exemple de comment supprimer une table dans une base de données avec le framework web django [TOC] ### Start django database shell Dans le terminal allez dans le dossier avec le fichier manage.py puis entrez la commande suivante : python manage.py dbshell Cela va démarrer un shell associé avec le type de la base de données. Par exemple, avec le SQLite par défaut, il retournera : SQLite version 3.35.4 2021-04-02 15:20:15 Enter ".help" for usage hints. sqlite> ### Avec ...

How to remove, drop a table in a database with the django web framework ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    21 mars 2022    /    : 56

Example of how to drop a table in a database with django: [TOC] ### Start django database shell In the terminal go the the folder with the manage.py file and then enter the following command: python manage.py dbshell It is going to start a shell associated with the database type. For example with the default SQLite it will returns: SQLite version 3.35.4 2021-04-02 15:20:15 Enter ".help" for usage hints. sqlite> ### SQLite database #### Get all tables name To ge ...

Comment obtenir des données json à partir d'une URL en utilisant uniquement javascript ?

Article    /    Bazinga    /    CC BY-SA 4.0    /    20 mars 2022    /    : 45

Exemples de comment obtenir des données json à partir d'une URL en utilisant uniquement javascript: [TOC] ### Video: tips For Using Async/Await in JavaScript Mon objectif est de supprimer JQuery de mes sites afin d'augmenter le vitesse sur mobile de ces derniers. Pour cela il est interessant de savoir par exemple comment obtenir des données json à partir d'une URL en utilisant uniquement javascript (AJAX calls). Il y a plusieurs docs disponibles sur le web (voir les références ci-dessou ...

How to get json data from a url using vanilla javascript only ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    20 mars 2022    /    : 1332

Examples of how to get json data from a url using only vanilla javascript: [TOC] ### Video: tips For Using Async/Await in JavaScript I was looking for to remove JQuery and replace it by only vanilla javascript to increase the speed of my websites (in particular by replacing all ajax calls that retrieve json data from n url). Found a lot of documentations online (see references below) but the following youtube video by James Q. Quick summarized everything very well: [youtube_video_id: ...

How to do SEO for a new website?

Article    /    go_toufiq    /    Public Domain    /    15 mars 2022    /    : 59

# Learn SEO In fact, it is not possible to finish a single article on how to do website [SEO](http://https://www.fiverr.com/go_toufiq/fix-google-search-console-index-coverage-errors-and-setup-analytics). You can get free advice on how to do ACO for your website from us (link). SEO is basically about managing your website by following the current information rules. Regularly and follow different updates and changes of SEO from time to time. However, SEO work is basically started through some bas ...

How to create a string variable on multiple lines in javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    09 mars 2022    /    : 50

Examples of how to create a string variable on multiple lines in javascript [TOC] ### Example 1 To create a string variable on multiple lines in javascript, a solution is to use a [template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) which is delimited by backticks ``: var s = `an example of a very very very very very very very very very veryvery very long string` console.log( s ); ### Example 2 Another exampl ...

How to add text in a html page using javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    08 mars 2022    /    : 65

Examples of how to add text in a html page using javascript: [TOC] ### Add text using innerHTML <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> </head> <body> <div id="intro"> <h1>Learning Javascript</h1> <p>First paragraph</p> </div> <script> document.querySelector("#intro").innerHTML += "<p>Second paragraph</p>"; </script> </body> </html> [images:learning-javascript-ad ...

Image    /    Daidalos    /    CC BY-SA 4.0    /    08 mars 2022    /    : 0

Image    /    Daidalos    /    CC BY-SA 4.0    /    08 mars 2022    /    : 0

How to check if a string contains another string (substring) in javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    04 mars 2022    /    : 79

Examples of how to test if a string contains another string (substring) in javascript: [TOC] ### Check if a string contains another string in javascript Let's consider the following string: var s = 'Tokyo is the most populated city in the world' To check for example if s contains the word 'city', a solution is to use [includes()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes): console.log( s.includes('city') ); returns he ...

How to convert a string representation of a number into a integer with javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    03 mars 2022    /    : 63

Examples of how to convert a string representation of a number into a integer with javascript : [TOC] ### Convert a string into an integer Let's consider the following variable var s = '42' The variable type can be checked using typeof console.log( typeof s ); gives here string To convert the above string into a integer, a solution is to use [parseInt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) var i = parseInt(s ...

How to create a date object in javascript for the current date or for a given year, month and day ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    02 mars 2022    /    : 74

Examples of how to create a date object in javascript: [TOC] ### Create a date object in javascript for the current date To create a date object in javascript there is the [Date() constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date). A simple utilisation of date() is to get the current date: var now = new Date(); console.log( now ); returns for example Wed Mar 02 2022 13:46:30 GMT-0500 (Eastern Standard Time) ### Cre ...

How to add an element to an array in javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    02 mars 2022    /    : 107

Examples of how to add an element to an array in javascript: [TOC] ### Add an element at the end of an array using push() Let's create a simple array: var A = [1,2,3,4]; console.log( A ); gives [1, 2, 3, 4] To append a new element at the end a solution is to use push(). An example, add the element 5 to the matrix A: A.push(5); console.log( A ); gives [1, 2, 3, 4, 5] var A = [1,2,3,4]; var B = [5,6]; A.push(B); console.log( A ); gives ...

How to loop over an array in javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    01 mars 2022    /    : 79

Examples of how to loop over each items of an array in javascript: [TOC] ### Create an array in javascript Let's create a very simple array in javascript var data = [9,5,7,3,1,4]; Note that we can test if it is an array using the following method: console.log( Array.isArray(data) ); which gives True here. To get the size of an array: console.log( data.length ); gives 6 And to get a given element by index: console.log( data[0] ); re ...

How to save the architecture of a tensorflow model (summary) in a json file ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    23 février 2022    /    : 140

Example of how to show save the architecture of a tensorflow model (summary) in a json file: [TOC] ### Create a model Let's create a simple untrained model with TensorFlow: from keras.utils.data_utils import get_file from tensorflow import keras from tensorflow.keras import layers model = keras.Sequential([ layers.Dense(20, activation='relu', input_shape=[11]), layers.Dense(10, activation='relu'), layers.Dense(10, activation='relu'), ...

How to filter dataframe rows using a OR statement with pandas ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    21 février 2022    /    : 151

Examples of how to filter dataframe rows using multiple conditions with OR in pandas: [TOC] ### Create a dataframe with pandas Let's first create a dataframe with pandas using a dictionary: import pandas as pd import numpy as np data= {'A':[-1,-2,3,4,5], 'B':[6,-7,8,9,-10], 'C':[11,12,13,14,15],} df = pd.DataFrame(data) returns here A B C 0 -1 6 11 1 -2 -7 12 2 3 8 13 3 4 9 14 4 5 - ...

How to check if a variable is a string in javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    15 février 2022    /    : 200

Examples of how to check if a variable is a string in javascript: [TOC] ### String variable Create a string var s = 'Hello world !' to check if it is a string a solution is to use typeof: console.log(typeof s === 'string'); gives here true Check if it is a string object: console.log(s instanceof String); gives false ### String object Create a string object var sobj = new String('Hello World !'); console.log(typeof sobj === 'string'); gi ...

How to convert a string object representation to a string in javascript ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    15 février 2022    /    : 172

Examples of how to convert a string object representation to a string in javascript: [TOC] ### Create a string object To create a string object a solution is to use [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) let mystringobj = new String('Hello World !'); then if we test that mystringobj is a string console.log(typeof mystringobj === 'string'); it returns false However if we test if it is a instanceof String ...

How to create an array in javascript and get an element by index ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    14 février 2022    /    : 176

Examples of how to create an array in javascript and get an element by index: [TOC] ### Create an array in javascript Examples of how to create arrays in javascript var data_1 = [1,2,3,4]; var data_2 = [1,['Ben','Tom','Jess'],3,4]; var data_3 = [[1,2],[3,4],[5,6]]; ### Get array length To get array's length: data_1.length; gives 4 For the second array data_2.length; gives 4 and the the third array: data_2.length; gives 3 ### Ch ...

How to check if a javascript variable is an array ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    14 février 2022    /    : 167

Example of how to check if a javascript variable is an array: [TOC] ### Using Array.isArray() A solution to check if a javascript variable is an array is to use [Array.isArray()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray) var data = [1,2,3,4]; Array.isArray(data); returns here true while data = 3; returns False #### With a if statement var data = [1,2,3,4]; if (!Array.isArray(data)) { console.l ...

Image    /    Daidalos    /    CC BY-SA 4.0    /    14 février 2022    /    : 0

Image    /    Daidalos    /    CC BY-SA 4.0    /    14 février 2022    /    : 0

Image    /    Daidalos    /    CC BY-SA 4.0    /    14 février 2022    /    : 0

How to create a confusion matrix and extract the true and false positives and true and false negatives using scikit learn in python ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    14 février 2022    /    : 502

Examples of how to create a confusion matrix and infer the true positive, true negative, false positive and false negative values using scikit learn in python ? [TOC] ### Create a confusion matrix with scikit-learn To create a confusion matrix a solution is to use scikit-learn: from sklearn.metrics import confusion_matrix y_true = [1,1,0,0,1] y_pred = [1,1,1,0,1] cm = confusion_matrix(y_true, y_pred, labels=[0, 1]) print(cm) returns [[1 1] [0 3]] [image:c ...

How to assess if an expression is true in python using assert ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    13 février 2022    /    : 167

Examples of how to assess if an expression is true in python using assert: [TOC] ### Assert in python Assert is usfeull to debug a code by inserting assertions into a program: assert condition, 'error message' It is equivalent to : if not condition: raise AssertionError('error message') ### Assert that a variable is a string An example s = 'Hello' assert type(s) == str, 'Oups, it is not a string variable !!' will returns nothing since s is a string here. ...

How to save a Tensorflow / Keras model weights in a HDF file ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    13 février 2022    /    : 218

Example of how to save a tensorflow model [TOC] ### Create a model Let's create and compile a model with Tensorflow from keras.utils.data_utils import get_file from tensorflow import keras from tensorflow.keras import layers model = keras.Sequential([ layers.Dense(20, activation='relu', input_shape=[11]), layers.Dense(10, activation='relu'), layers.Dense(10, activation='relu'), layers.Dense(1, activation='sigmoid') ]) ...

How to replace dataframe columns by another dataframe columns with pandas ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    09 février 2022    /    : 346

Examples of how to replace dataframe columns by another dataframe columns with pandas [TOC] ### Dataframe 1 Let's create a first dataframe with pandas import pandas as pd import random import numpy as np data = np.arange(40) data = data.reshape((10,4)) categorical_data = ['M', 'M', 'F', 'F', 'F'] gender_list = [random.choice(categorical_data) for i in range( data.shape[0] )] label_list = [random.choice([0,1]) for i in range( data.shape ...

How to apply a one hot encoding to a pandas dataframe categorical data column using get_dummies() ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    08 février 2022    /    : 476

Examples of how to apply a one hot encoding to a pandas dataframe categorical data column in python ? [TOC] ### Create two dataframes with pandas So, let's first create a fake dataset stored in a pandas dataframe: import pandas as pd import random import numpy as np categorical_data_1 = ['Paris', 'London', 'New-York', 'Berlin', 'Moscow'] categorical_data_2 = ['M', 'M', 'F', 'F', 'F'] data = np.arange(100) data = data.reshape((25,4)) loca ...

Image    /    Daidalos    /    CC BY-SA 4.0    /    07 février 2022    /    : 0

How to add a border (frame) to an image using python ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    07 février 2022    /    : 303

Examples of how to add a border (frame) to an image (picture) using python: [TOC] #### Import an image Let's first import an image using python (for example [Eiffel Tower](https://en.wikipedia.org/wiki/Eiffel_Tower#/media/File:Tour_Eiffel_Wikimedia_Commons.jpg)): from matplotlib import image import matplotlib.pyplot as plt img = image.imread("eiffel-tower.jpeg") plt.imshow(img) plt.show() print(img.shape) [image:rgb-image-rotation-scipy-matplotlib-01 size:75 ...

Image    /    Daidalos    /    CC BY-SA 4.0    /    07 février 2022    /    : 0

Image    /    Daidalos    /    CC BY-SA 4.0    /    07 février 2022    /    : 0

Image    /    Daidalos    /    CC BY-SA 4.0    /    07 février 2022    /    : 0

Image    /    Daidalos    /    CC BY-SA 4.0    /    07 février 2022    /    : 0

How to pad a numpy array in python ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    06 février 2022    /    : 275

Examples of how to pad a numpy array in python: [TOC] ### Create a 2D array with numpy Let's consider the following array: \begin{equation} A = \left( \begin{array}{ccc} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9 \end{array}\right) \end{equation} that can be implemented using numpy and python: import numpy as np A = np.arange(0,12) A = A.reshape(4,3) print(A) gives [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]] and print( A.shape ) ...

How to extract first letter of each word in a sentence with python using a regular expression ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    31 janvier 2022    /    : 284

Example of how to extract first letter of each word in a sentence with python using a regular expression: [TOC] ### Using a python regular expression Let's consider the following sentence: import re s = 'Hello, how are you today' to extract first letter of each word: re.findall(r'\b([a-zA-Z]|\d+)', s) gives ['H', 'h', 'a', 'y', 't'] Note that l = re.findall(r'\b([a-zA-Z]|\d+)', s) print(type(l) ) returns a list <class 'list' ...

How to merge (concatenate) two or more dataframe columns into one column with pandas ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    31 janvier 2022    /    : 513

Examples of how to merge (concatenate) two columns into one with pandas: [TOC] ### Merge two or more dataframe columns of strings with pandas Let's first create a dataframe with pandas import pandas as pd import numpy as np data = {'First_Name':['April','Emory','David','Alice','Virginia'], 'Last_Name':['Reiter','Miller','Ballin','Trotter','Rios'], 'Middle_Name':['G.','','H.G','',''], 'Age':[42,24,12,32,56]} df = pd.DataFra ...

How to split a full name column into a first and last name columns with pandas in python ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    31 janvier 2022    /    : 522

Examples of how to split a full name column into a first and last name columns with pandas in python: [TOC] ### Create a dataframe with pandas Let's first create a dataframe with pandas: import pandas as pd import numpy as np data = {'Full_Name':['April Reiter','Emory Miller','David Ballin','Alice Trotter','Virginia Alicia Rios']} df = pd.DataFrame(data=data) print(df) gives Full_Name 0 April Reiter 1 Emory Miller 2 ...

How to create a new column of initials from a full name dataframe column with pandas and python ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    28 janvier 2022    /    : 416

Example of how to create initials from a full name dataframe column with pandas and python: [TOC] ### Create a dataframe with pandas Let's first create a data with pandas with a column with full names: import pandas as pd import numpy as np data = {'Full_Name':['April Reiter','Emory Miller','David Ballin','Alice Trotter','Virginia Rios']} df = pd.DataFrame(data=data) print(df) gives Full_Name 0 April Reiter 1 Emory Miller 2 David Ballin 3 Ali ...

How to find all dataframe columns that contain a given word with pandas ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    26 janvier 2022    /    : 433

Examples of how to find all dataframe columns that contain a given word with pandas [TOC] ### Create a dataframe with pandas Let's first create a dataframe with pandas import pandas as pd import numpy as np data = np.arange(1,33) data = data.reshape(4,8) df = pd.DataFrame(data=data,columns=['name','address_01','address_02','address_03', 'full address name','street address','zip code','county']) print(df) returns name address_01 addres ...

How to select dataframe columns that end with *** with pandas ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    26 janvier 2022    /    : 308

Examples of how to select (filter) dataframe columns that end with *** with pandas: [TOC] ### Create a dataframe with pandas Let's first create a dataframe with pandas import pandas as pd import numpy as np data = np.arange(1,33) data = data.reshape(4,8) df = pd.DataFrame(data=data,columns=['product_l1','product_l2','product_l3','product_l4','product_id', 'product_01_name','product_02_name','product_source']) print(df) returns product_l ...

How to store a pandas dataframe into a json file ?

Article    /    Daidalos    /    CC BY-SA 4.0    /    25 janvier 2022    /    : 353

Examples of how to store (convert/transform) a pandas dataframe into a json file [TOC] ### Create a dataframe with pandas Let's first create a simple dataframe: import pandas as pd import numpy as np data = np.random.randint(99, size=(3,3)) df = pd.DataFrame(data=data,columns=['A','B','C']) print(df) returns for example A B C 0 78 96 0 1 4 32 76 2 72 16 74 ### Convert the dataframe into a json string representation To convert a datfr ...