Pandas Dataframe describe method Implementation With Examples

Pandas Dataframe describe method Implementation With Examples

GET FREE AMZAON AUDIOBOOKS

Pandas is a great python module for data manipulation. There are many functions in it that make your task easy. The pandas.DataFrame.describe() is one of them and it allows you to generate descriptive statistics like mean, max, min, std (standard deviation) e.t.c. In this entire tutorial, you will learn to implement the pandas dataframe describe() method with examples.

Examples of Pandas Dataframe Describe

In this section, you will know all the examples on how to get statistics of dataframe and series using the describe() method.

Example 1: Applying Pandas Dataframe Describe on Series

In this example, first you will create a series and apply describe() method to it. You can create series using the Series() method. Execute the below lines of code.

import pandas as pd
series = pd.Series([10,20,30,40,50,60])
print(series.describe())

Output

Applying Pandas Describe method on Series
Applying Pandas Describe method on Series

You can see I have got all the statistics values like min, count, std, max e.t.c.

 

Example 2: Apply Pandas Describe on Categorical Series

Now suppose you have categorical data or Series and want to describe it. Then also you can use the describe() function. You can find count, unique, frequency of value e.t.c using it. Run the below lines of code and see the output.

import pandas as pd
cat_series = pd.Series(["a","b","a","c","d","d","c"])
print(cat_series.describe())

Output

Applying Pandas Describe method on Categorical Series
Applying Pandas Describe method on Categorical Series

Example 3: Apply Pandas Describe on Mix data (Numeric and Categorical)

In this example, I will create a Dataframe that has both numeric and categorical data columns. After that, I will use the panda’s dataframe describe()¬† method to find the statistics on numeric, categorical, or whole data frame.

Let’s create a Sample Dataframe.

import pandas as pd
cat_data = pd.Categorical(["x","y","z"])
num_data = [10,20,30]
data = {"categorical_data_col":cat_data,"numeric_data_col":num_data}
df = pd.DataFrame(data)
print(df)

Output

Sample Dataframe for pandas describe() method
Sample Dataframe for pandas describe() method

Finding Statistics on Numeric Column

By default, if you apply describe() method then you will get statistics on the numeric column. You can also use the df.column_name.describe() method to find statistics on numeric column.

Run the below lines of code and see the output.

print(df.describe())

Output

Deafult output of the numeric column after using describe method
The default output of the numeric column after using describe the method

 

Finding Statistics on Categorical Column

To describe a categorical column you have to use the column name to do so. Execute the below lines of code.

print(df.categorical_data_col.describe())

Output

Finding Statistics on Categorical Column
Finding Statistics on Categorical Column

Describe all columns of the dataframe

You can also describe all columns of the dataframe bypassing¬† include=’all’ as an argument inside the describe() method.

print(df.describe(include="all"))

Output

Applying Pandas Describe method on Whole Dataframe
Applying Pandas Describe method on the Whole Dataframe

Conclusion

Pandas Dataframe describe() method is very useful in finding the statistics of numeric or categorical data quickly. In fact, It helps you manipulate or find patterns in the dataframe. These are the examples I have compiled for you. I hope this tutorial has cleared your queries on it. Even if you have doubts then you can contact us for more help.

Source:

Pandas Describe Documentation

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner