Programming Articles - Page 1046 of 3363

Express.js – app.delete() Method

Mayank Agarwal
Updated on 30-Sep-2021 12:09:47

7K+ Views

The app.delete() method routes all the HTTP DELETE requests to the specified path with the specified callback functions.Syntaxapp.delete(path, callback, [callback])Parameterspath − This is the path for which the middleware function is invoked. A path can be a string, path pattern, a regular expression, or an array of all these.callback − These are the middleware functions or a series of middleware functions that act like a middleware except that these callbacks can invoke next (route).Example 1Create a file "appDelete.js" and copy the following code snippet. After creating the file, use the command "node appDelete.js" to run this code.// app.delete() Method Demo ... Read More

Python Pandas - Draw a set of vertical point plots grouped by a categorical variable with Seaborn

AmitDiwan
Updated on 30-Sep-2021 12:05:47

222 Views

Point Plot in Seaborn is used to show point estimates and confidence intervals using scatter plot glyphs. The seaborn.pointplot() is used for this. For vertical point plot grouped by a categorical variable, set the variable as a value for the pointplot().Let’s say the following is our dataset in the form of a CSV file − Cricketers.csvAt first, import the required libraries −import seaborn as sb import pandas as pd import matplotlib.pyplot as pltLoad data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers.csv") Vertical point plot grouped by a categorical variable −sb.pointplot(dataFrame['Role'], dataFrame['Age'])ExampleFollowing is the code −import seaborn ... Read More

Express.js – app.all() Method

Mayank Agarwal
Updated on 30-Sep-2021 12:01:14

3K+ Views

The app.all() method can be used for all types of routings of a HTTP request, i.e., for POST, GET, PUT, DELETE, etc., requests that are made to any specific route. It can map app types of requests with the only condition that the route should match.Syntaxapp.path(path, callback, [callback])Parameterspath − This is the path for which the middleware function is invoked. A path can be a string, path pattern, a regular expression or an array of all these.callback − These are the middleware functions or a series of middleware functions that act like a middleware except that these callbacks can invoke ... Read More

Python Pandas - Replace all NaN elements in a DataFrame with 0s

AmitDiwan
Updated on 30-Sep-2021 11:59:22

351 Views

To replace NaN values, use the fillna() method. Let’s say the following is our CSV file opened in Microsoft Excel with some NaN values −At first, import the required library −import pandas as pdLoad data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")Replace NaN values with 0s using the fillna() method −dataFrame.fillna(0)ExampleFollowing is the codeimport pandas as pd # Load data from a CSV file into a Pandas DataFrame dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv") print("DataFrame...", dataFrame) # replace NaN values with 0s res = dataFrame.fillna(0) print("DataFrame after replacing NaN values...", res)OutputThis will produce the following output −DataFrame... ... Read More

Python Pandas - Draw a set of vertical bar plots grouped by a categorical variable with Seaborn

AmitDiwan
Updated on 30-Sep-2021 11:52:52

520 Views

Bar Plot in Seaborn is used to show point estimates and confidence intervals as rectangular bars. The seaborn.barplot() is used for this. Plot vertical bar plots grouped by a categorical variable, by passing the variable as x or y coordinates in the barplot() method.Let’s say the following is our dataset in the form of a CSV file − Cricketers2.csvAt first, import the required libraries −import seaborn as sb import pandas as pd import matplotlib.pyplot as pltLoad data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers2.csv")Plotting vertical bar plots grouped by a categorical variable −sb.barplot(x = dataFrame["Role"], y ... Read More

Python Pandas - Draw swarms of observations on top of a violin plot with Seaborn

AmitDiwan
Updated on 30-Sep-2021 11:50:20

608 Views

Swarm Plot in Seaborn is used to draw a categorical scatterplot with non-overlapping points. The seaborn.swarmplot() is used for this. Draw swarms of observations on top of a violin plot using the violinplot().Let’s say the following is our dataset in the form of a CSV file − Cricketers2.csvAt first, import the required libraries −import seaborn as sb import pandas as pd import matplotlib.pyplot as pltLoad data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers2.csv")Draw swarms of observations on top of a violin plot −sb.violinplot(x = dataFrame["Role"], y = dataFrame["Matches"]) sb.swarmplot(x = dataFrame["Role"], y = dataFrame["Matches"], color="white")ExampleFollowing is ... Read More

Python - Read csv file with Pandas without header?

AmitDiwan
Updated on 26-Aug-2023 08:31:46

38K+ Views

To read CSV file without header, use the header parameter and set it to “None” in the read_csv() method.Let’s say the following are the contents of our CSV file opened in Microsoft Excel −At first, import the required library −import pandas as pdLoad data from a CSV file into a Pandas DataFrame. This will display the headers as well −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")While loading, use the header parameter and set None to load the CSV without header −pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv", header=None)ExampleFollowing is the code −import pandas as pd # Load data from a CSV file into a Pandas DataFrame dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv") ... Read More

Python - Draw a Scatter Plot for a Pandas DataFrame

AmitDiwan
Updated on 30-Sep-2021 11:39:36

748 Views

Scatter Plot is a data visualization technique. Use the plot.scatter() to plot the Scatter Plot. At first, Let us import the required libraries −We have our data with Team Records. Set it in the Pandas DataFrame −data = [["Australia", 2500], ["Bangladesh", 1000], ["England", 2000], ["India", 3000], ["Srilanka", 1500]] dataFrame = pd.DataFrame(data, columns=["Team", "Rank_Points"]) Let us plot now with the columns −dataFrame.plot.scatter(x="Team", y="Rank_Points")ExampleFollowing is the code −import pandas as pd import matplotlib.pyplot as mp # our data data = [["Australia", 2500], ["Bangladesh", 1000], ["England", 2000], ["India", 3000], ["Srilanka", 1500]] # dataframe dataFrame = pd.DataFrame(data, columns=["Team", "Rank_Points"]) ... Read More

Rename column name with an index number of the CSV file in Pandas

AmitDiwan
Updated on 30-Sep-2021 11:36:14

2K+ Views

Using columns.values(), we can easily rename column name with index number of a CSV file.Let’s say the following are the contents of our CSV file opened in Microsoft Excel −We will rename the column names. At first, load data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")Display all the column names from the CSV −dataFrame.columnsNow, rename column names −dataFrame.columns.values[0] = "Car Names" dataFrame.columns.values[1] = "Registration Cost" dataFrame.columns.values[2] = "Units Sold"ExampleFollowing is the code −import pandas as pd # Load data from a CSV file into a Pandas DataFrame: dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv") print("Reading the CSV file...", dataFrame) ... Read More

Select rows that contain specific text using Pandas

AmitDiwan
Updated on 30-Sep-2021 11:29:38

853 Views

To select rows that contain specific text, use the contains() method. Let’s say the following is our CSV file path −C:\Users\amit_\Desktop\SalesRecords.csvAt first, let us read the CSV file and create Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")Now, let us select rows that contain specific text “BMW” −dataFrame = dataFrame[dataFrame['Car'].str.contains('BMW')]ExampleFollowing is the code −import pandas as pd # reading csv file dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv") print("DataFrame...", dataFrame) # select rows containing text "BMW" dataFrame = dataFrame[dataFrame['Car'].str.contains('BMW')] print("Fetching rows with text BMW ...", dataFrame)OutputThis will produce the following output −DataFrame ...            Car       Place   UnitsSold ... Read More

Advertisements