Express.js App All Methods

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

Replace All NaN Elements in a DataFrame with 0s in Python Pandas

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

331 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

Draw Vertical Bar Plots Grouped by Categorical Variable with Seaborn

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

497 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

Draw Swarms of Observations on Violin Plot with Seaborn

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

598 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

Draw a Scatter Plot for a Pandas DataFrame in Python

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

721 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 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

837 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

Plot Density Map in Python using Matplotlib

Rishikesh Kumar Rishi
Updated on 29-Sep-2021 12:38:42

4K+ Views

To plot a density map in Python, we can take the following steps −Create side, x, y, and z using numpy. Numpy linspace helps to create data between two points based on a third number.Return coordinate matrices from coordinate vectors using side data.Create exponential data using x and y (Step 2).Create a pseudocolor plot with a non-regular rectangular grid using pcolormesh() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, cm, colors import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True side = np.linspace(-2, 2, 15) X, Y = np.meshgrid(side, side) Z = np.exp(-((X - 1) ... Read More

Merge DataFrame with Many-to-One Relation in Python Pandas

AmitDiwan
Updated on 29-Sep-2021 11:50:28

2K+ Views

To merge Pandas DataFrame, use the merge() function. The many-to-one relation is implemented on both the DataFrames by setting under the “validate” parameter of the merge() function i.e. −validate = “many-to-one” or validate = “m:1”The many-to-one relation checks if merge keys are unique in right dataset.At first, let us create our 1st DataFrame −dataFrame1 = pd.DataFrame(    {       "Car": ['BMW', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 110, 80, 110, 90] } ) Now, let us create our 2nd DataFrame −dataFrame2 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', ... Read More

Select Multiple Columns from a Pandas DataFrame in Python

AmitDiwan
Updated on 29-Sep-2021 11:41:31

3K+ Views

Let’s say the following are the contents of our CSV file opened in Microsoft Excel −At first, load data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")To select multiple column records, use the square brackets. Mention the columns in the brackets and fetch multiple columns from the entire dataset −dataFrame[['Reg_Price', 'Units']] 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) # displaying two columns res = dataFrame[['Reg_Price', 'Units']]; print("Displaying two columns : ", res)OutputThis will produce the ... Read More

Advertisements