Found 26504 Articles for Server Side Programming

Python - Create a Time Series Plot using Line Plot with Seaborn

AmitDiwan
Updated on 01-Oct-2021 11:49:00

344 Views

To create a Time Series Plot, use the lineplot(). At first, import the required libraries −import seaborn as sb import pandas as pd import matplotlib.pyplot as pltCreate a DataFrame with one of the columns as date i.e. “Date_of_Purchase” −dataFrame = pd.DataFrame({'Date_of_Purchase': ['2018-07-25', '2018-10-25', '2019-01-25', '2019-05-25', '2019-08-25', '2020-09-25', '2021-03-25'], 'Units Sold': [98, 77, 45, 70, 70, 87, 66] })Pot Time Series using lineplot() −sb.lineplot(x="Date_of_Purchase", y="Units Sold", data=dataFrame) ExampleFollowing is the code −import seaborn as sb import pandas as pd import matplotlib.pyplot as plt # creating DataFrame dataFrame = pd.DataFrame({'Date_of_Purchase': ['2018-07-25', '2018-10-25', '2019-01-25', '2019-05-25', '2019-08-25', '2020-09-25', '2021-03-25'], 'Units Sold': [98, 77, ... Read More

Python - How to Count the NaN Occurrences in a Column in Pandas Dataframe?

AmitDiwan
Updated on 01-Oct-2021 11:45:18

804 Views

To count the NaN occurrences in a column, use the isna(). Use the sum() to add the values and find the count.At first, let us import the required libraries with their respective aliases −import pandas as pd import numpy as npCreate a DataFrame. We have set the NaN values using the Numpy np.inf in “Units_Sold” column −dataFrame = pd.DataFrame({"Car": ['BMW', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', 'Jaguar'], "Cubic_Capacity": [2000, 1800, 1500, 2500, 2200, 3000], "Reg_Price": [7000, 1500, 5000, 8000, 9000, 6000], "Units_Sold": [ 100, np.NaN, 150, np.NaN, 200, np.NaN] })Count NaN values from column "Units_Sold" −dataFrame["Units_Sold"].isna().sum() ExampleFollowing is the code −import pandas ... Read More

Python Pandas – Merge DataFrame with one-to-one relation

AmitDiwan
Updated on 01-Oct-2021 11:40:15

1K+ Views

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

Python Pandas – Propagate non-null values forward

AmitDiwan
Updated on 01-Oct-2021 11:35:29

666 Views

Use the “method” parameter of the fillna() method. For forward fill, use the value ‘ffill’ as shown below −fillna(method='ffill')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 pd Load data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")ExampleFollowing is the complete 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("DataFrame...", dataFrame) # propagate non null values forward res = dataFrame.fillna(method='ffill') print("DataFrame after forward fill...", res)OutputThis will produce the ... Read More

Plot the dataset to display Downtrend – Python Pandas

AmitDiwan
Updated on 01-Oct-2021 11:31:19

95 Views

Downward pattern displayed by Time Series Analysis is what we call Downtrend. Let’s say the following is our dataset i.e. SalesRecords2.csvAt first, import the required libraries −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\SalesRecords2.csv") Casting column to datetime object −dataFrame['Sold_On'] = pd.to_datetime(dataFrame['Sold_On'])Create the plot for downtrend −dataFrame.plot() ExampleFollowing is the code −import pandas as pd import matplotlib.pyplot as plt # Load data from a CSV file into a Pandas DataFrame dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesRecords2.csv") print("Reading the CSV file...", dataFrame) # casting column to datetime object dataFrame['Sold_On'] = ... Read More

Plot the dataset to display Uptrend – Python Pandas

AmitDiwan
Updated on 01-Oct-2021 11:27:48

157 Views

Upward pattern displayed by Time Series Analysis is what we call Uptrend. Let’s say the following is our dataset i.e. SalesRecords.csvAt first, import the required libraries −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\SalesRecords.csv")Casting column to datetime object −dataFrame['Date_of_Purchase'] = pd.to_datetime(dataFrame['Date_of_Purchase'])Create the plot for uptrend −dataFrame.plot()ExampleFollowing is the code −import pandas as pd import matplotlib.pyplot as plt # Load data from a CSV file into a Pandas DataFrame dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesRecords.csv") print("Reading the CSV file...", dataFrame) # casting column to datetime object dataFrame['Date_of_Purchase'] = pd.to_datetime(dataFrame['Date_of_Purchase']) ... Read More

Create a Pipeline and remove a row from an already created DataFrame - Python Pandas

AmitDiwan
Updated on 01-Oct-2021 11:22:19

331 Views

Use the ValDrop() method of pdpipe library to remove a row from an already create Pandas DataFrame. At first, import the required pdpipe and pandas libraries with their respective aliases −import pdpipe as pdp import pandas as pdLet us create a DataFrame. Here, we have two columns −dataFrame = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Now, remove a row using valdDrop() method −dataFrame = pdp.ValDrop(['Jaguar'], 'Car').apply(dataFrame) ExampleFollowing is the complete code −import pdpipe as pdp import pandas as pd # function ... Read More

Express.js – app.METHOD() in Method

Mayank Agarwal
Updated on 01-Oct-2021 07:23:47

456 Views

app.METHOD() is used for mapping or routing an HTTP request where METHOD represents the HTTP method of the request such as GET, POST, PUT, etc., but in lowercase. Therefore, the methods are app.get(), app.post(), app.get(), and so on.Syntaxapp.METHOD(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 acts like a middleware except that these callbacks can invoke next (route).Example 1Create a file "appMethod.js" and copy ... Read More

Using next() function in Express.js

Mayank Agarwal
Updated on 01-Oct-2021 06:54:31

1K+ Views

Express.js is a powerful tool for building web servers to hit API at backend. It has several advantages which makes it popular, however it has got some drawbacks too, for example, one needs to define different routes or middleware to handle different incoming requests from the client.In this article, we will see how to use the next() function in a middleware of Express.js. There are lots of middleware in Express.js. We will use the app.use() middleware to define the handler of the particular request made by client.Syntaxapp.use(path, (req, res, next) )Parameterspath – This is the path for which the middleware ... Read More

Express.js – express.text() function

Mayank Agarwal
Updated on 01-Oct-2021 06:44:18

935 Views

express.text() is a built-in middleware function in Express. It parses the incoming request payloads into a string and it is based upon the body-parser. This method returns the middleware that parses all the bodies as strings.Syntaxexpress.text([options])ParametersFollowing are the different options available with this methodoptionsinflate – It enables or disables the handling of the deflated or compressed bodies. Default: truelimit – It controls the maximum size of the request body.defaultCharset – This option specifies the default character set for the text content if the charset is not specified in the Content-type header of the request.type – It determines the media type ... Read More

Advertisements