Python - Find the Summary of Statistics of a Pandas DataFrame

PythonServer Side ProgrammingProgramming

To find the summary of statistics of a DataFrame, use the describe() method. At first, we have imported the following pandas library with an alias

import pandas as pd

Following 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 DataFrame −

dataFrame.describe()

Example

Following is the complete code

import pandas as pd

# reading csv file
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\CarRecords.csv")
print("DataFrame...\n",dataFrame)

# count the rows and columns in a DataFrame
print("\nNumber of rows and column in our DataFrame = ",dataFrame.shape)

# summary of DataFrame
print("\nGet the summary of statistics of a DataFrame = \n",dataFrame.describe())

# returns top 7 row records
print("\nDataFrame with specific number of rows...\n",dataFrame.head(7))

Output

This will produce the following output

DataFrame...
           Car       Place   UnitsSold
0         Audi   Bangalore          80
1      Porsche      Mumbai         110
2   RollsRoyce        Pune         100
3          BMW       Delhi          95
4     Mercedes   Hyderabad          80
5  Lamborghini  Chandigarh          80
6         Audi      Mumbai         100
7     Mercedes        Pune         120
8  Lamborghini       Delhi         100

Number of rows and colums in our DataFrame = (9, 3)

Get the summarry of statistics of a DataFrame =
       UnitsSold
count   9.000000
mean   96.111111
std    14.092945
min    80.000000
25%    80.000000
50%   100.000000
75%   100.000000
max   120.000000

DataFrame with specific number of rows ...
           Car       Place   UnitsSold
0         Audi   Bangalore          80
1      Porsche      Mumbai         110
2   RollsRoyce        Pune         100
3          BMW       Delhi          95
4     Mercedes   Hyderabad          80
5  Lamborghini  Chandigarh          80
6         Audi      Mumbai         100
raja
Published on 27-Sep-2021 13:39:39
Advertisements