Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 904 of 2650
814 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
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
677 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
100 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
161 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
340 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
466 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
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
945 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
2K+ Views
express.raw() is a built-in middleware function in Express. It parses the incoming requests into a buffer and it is based upon the body-parser. This method returns the middleware that parses all JSON bodies as buffer and only looks at the requests where the content-type header matches the type option.Syntaxexpress.raw([options])ParametersFollowing are the different options available with this methodoptions –inflate – This enables or disables the handling of the deflated or compressed bodies. Default: truelimit – Controls the maximum size of the request body.type – Determines the media type for the middleware that will be parsed.Example 1Create a file with the name "expressRaw.js" ... Read More