Found 26504 Articles for Server Side Programming

Express.js – app.locals Property

Mayank Agarwal
Updated on 30-Sep-2021 13:35:14

1K+ Views

The app.locals object defines the properties that are local variables inside an application. Once the value of app.locals property is set, it persists throughout the life of the application. The res.locals property is valid only for the lifetime of the request.Syntaxapp.localsExample 1Create a file "appLocals.js" and copy the following code snippet. After creating the file, use the command "node appLocals.js" to run this code.// app.locals code Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); // Setting the below email throught out the application ... Read More

Express.js – app.listen() Method

Mayank Agarwal
Updated on 30-Sep-2021 13:29:13

8K+ Views

The app.listen() method binds itself with the specified host and port to bind and listen for any connections. If the port is not defined or 0, an arbitrary unused port will be assigned by the operating system that is mainly used for automated tasks like testing, etc.The app object returned by express() is a JavaScript function, that is passed to Node’s HTTP servers as a callback which handles the requests. This makes the application to provide both HTTP and HTTPS versions of the same app with the same code base, as the app does not inherit from these.Syntaxapp.listen([port], [host], [backlog], ... Read More

How to plot a Pandas Dataframe with Matplotlib?

AmitDiwan
Updated on 30-Sep-2021 13:09:09

1K+ Views

We can plot Line Graph, Pie Chart, Histogram, etc. with a Pandas DataFrame using Matplotlib. For this, we need to import Pandas and Matplotlib libraries −import pandas as pd import matplotlib.pyplot as pltLet us begin plotting −Line GraphExampleFollowing is the code −import pandas as pd import matplotlib.pyplot as plt # creating a DataFrame with 2 columns dataFrame = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'],          "Reg_Price": [2000, 2500, 2800, 3000, 3200, 3500], "Units": [100, 120, 150, 170, 180, 200] ... Read More

Python Pandas - Draw a point plot and show standard deviation of observations with Seaborn

AmitDiwan
Updated on 30-Sep-2021 13:02:56

744 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. Display Standard Deviation of Observations using confidence interval ci parameter value "sd" in the pointplot() method.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")Plotting point plot with “Academy” and “Age”. Display Standard Deviation of Observations using confidence interval parameter value "sd"sb.pointplot( ... Read More

Python Pandas - Draw a boxplot for each numeric variable in a DataFrame with Seaborn

AmitDiwan
Updated on 30-Sep-2021 12:59:12

2K+ Views

Box Plot in Seaborn is used to draw a box plot to show distributions with respect to categories. The seaborn.boxplot() is used for this. Use the "orient” parameter for orientation of each numeric variable.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")Plotting box plot using the orient parameter for orientation of each numeric variable −sb.boxplot( data = dataFrame, orient="h")ExampleFollowing is the code −import seaborn ... Read More

Python - How to Group Pandas DataFrame by Year?

AmitDiwan
Updated on 30-Sep-2021 12:58:20

2K+ Views

We will group Pandas DataFrame using the groupby(). Select the column to be used using the grouper function. We will group year-wise and calculate sum of Registration Price with year interval for our example shown below for Car Sale Records.At first, let’s say the following is our Pandas DataFrame with three columns −# dataframe with one of the columns as Date_of_Purchase dataFrame = pd.DataFrame(    {       "Car": ["Audi", "Lexus", "Tesla", "Mercedes", "BMW", "Toyota", "Nissan", "Bentley", "Mustang"],       "Date_of_Purchase": [pd.Timestamp("2021-06-10"),          pd.Timestamp("2019-07-11"),          pd.Timestamp("2016-06-25"),          pd.Timestamp("2021-06-29"), ... Read More

Python Pandas - Draw a bar plot and show standard deviation of observations with Seaborn

AmitDiwan
Updated on 30-Sep-2021 12:48:20

3K+ Views

Bar Plot in Seaborn is used to show point estimates and confidence intervals as rectangular bars. The seaborn.barplot() is used for this. Display Standard Deviation of Observations using confidence interval ci parameter value sd.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 bar plot with Academy and Matches. Display Standard Deviation of Observations using confidence interval parameter value "sd" −sb.barplot(x = "Academy", y = ... Read More

Python Pandas - Select a subset of rows and columns combined

AmitDiwan
Updated on 30-Sep-2021 12:43:42

906 Views

To select a subset of rows and columns, use the loc. Use the index operator i.e. the square bracket and set conditions in the loc.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")Select a subset of rows and columns combined. Right column displays the column you want to display i.e. Cars column here −dataFrame.loc[dataFrame["Units"] > 100, "Car"]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 Pandas - Draw a point plot and control order by passing an explicit order with Seaborn

AmitDiwan
Updated on 30-Sep-2021 12:38:06

481 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 explicit order, use the order parameter of the pointplot() method.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")Plotting point plot with “Academy” and “Age”. Control order by passing an explicit order i.e. ordering on the basis of "Academy". Ordering using ... Read More

Python Pandas - Draw a set of Horizontal point plots but do not draw lines to connect points with Seaborn

AmitDiwan
Updated on 30-Sep-2021 12:32:49

518 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. To avoid drawing lines to connect points, simply set the “join” parameter of the pointplot() method to False.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")Now, plot the Horizontal point plot. The “join” parameter is set as False to avoid drawing ... Read More

Advertisements