AmitDiwan has Published 10744 Articles

Python - Find the Summary of Statistics of a Pandas DataFrame

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 13:41:37

372 Views

To find the summary of statistics of a DataFrame, use the describe() method. At first, we have imported the following pandas library with an aliasimport pandas as pdFollowing is our CSV file and we are creating a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")Now, get the summary of statistics of our Pandas ... Read More

Python Pandas – Count the rows and columns in a DataFrame

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 13:29:08

653 Views

To count the rows and columns in a DataFrame, use the shape property. At first, let’s say we have the a CSV file on the Desktop as shown in the below path −C:\Users\amit_\Desktop\CarRecords.csvRead the CSV file −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv") Let us now count the rows and columns using shapedataFrame.shapeExampleFollowing is ... Read More

Python Pandas - Display specific number of rows from a DataFrame

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 13:19:53

4K+ Views

To display specific number of rows from a DataFrame, use the head() function. Set the parameter to be the number of row records to be fetched. For example, for 10 rows, mention −dataFrame.head(10)At first, let us import the required library with an alias −import pandas as pd Our CSV is ... Read More

Python Pandas - Iterate and fetch the rows that contain the desired text

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 13:13:57

224 Views

To iterate and fetch the rows containing the desired text, use the itertuples() and find() method. The itertuples() iterate over DataFrame rows.At first, let us import the required library with an alias −import pandas as pdOur CSV is on the Desktop as shown in the below path −C:\Users\amit_\Desktop\CarRecords.csv Let us ... Read More

Python - How to Merge all excel files in a folder

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 12:43:43

11K+ Views

To merge all excel files in a folder, use the Glob module and the append() method.Let’s say the following are our excel files on the Desktop −Sales1.xlsxSales2.xlsxNote − You may need to install openpyxl and xlrd packages.At first, set the path where all the excel files you want to merge ... Read More

How to Sort CSV by a single column in Python ?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 12:33:40

6K+ Views

To sort CSV by a single column, use the sort_values() method. Set the column using which you want to sort in the sort_values() method.At first, let’s read our CSV file “SalesRecords.csv”with DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesRecords.csv")Sort according to a single column “Car” −dataFrame.sort_values("Car", axis=0, ascending=True, inplace=True, na_position='first')Next, sort according to a ... Read More

Python - Read all CSV files in a folder in Pandas?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 12:15:29

6K+ Views

To read all excel files in a folder, use the Glob module and the read_csv() method. Let’s say the following are our excel files in a directory −At first, let us set the path and get the csv files. Our CSV files are in the folder MyProject −path = "C:\Users\amit_\Desktop\MyProject\"Read ... Read More

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

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 12:05:11

242 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 box plot using the seaborn.boxplot().Let’s say the following is our dataset in the form of a CSV file −Cricketers2.csvAt first, import the ... Read More

Python Pandas - Draw a swarm plot and control swarm order by passing an explicit order with Seaborn

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 11:57:11

649 Views

Swarm Plot in Seaborn is used to draw a categorical scatterplot with non-overlapping points. The seaborn.swarmplot() is used for this. Control swarm order by passing an explicit order i.e. ordering on the basis of a specific column using the order parameter −Let’s say the following is our dataset in the ... Read More

Python Pandas - Group the swarms by two categorical variables with Seaborn

AmitDiwan

AmitDiwan

Updated on 27-Sep-2021 11:47:21

433 Views

Swarm Plot in Seaborn is used to draw a categorical scatterplot with non-overlapping points. The seaborn.swarmplot() is used for this. To group the swarms by two categorical variables, set those variables in the swarmplot() using the x, y or hue parameters.Let’s say the following is our dataset in the form ... Read More

Advertisements