Pandas Tutorial
Creating Objects
Viewing Data
Selection
Manipulating Data
Grouping Data
Merging, Joining and Concatenating
Working with Date and Time
Working With Text Data
Working with CSV and Excel files
Operations
Visualization
Applications and Projects
One of the most useful features of pandas is its ability to quickly provide basic statistical details of a DataFrame. Here's how you can achieve that.
First, make sure you've got pandas installed:
pip install pandas
import pandas as pd
data = { 'A': [1, 2, 3, 4, 5], 'B': [5, 6, 7, 8, 9], 'C': [9, 8, 7, 6, 5] } df = pd.DataFrame(data) print(df)
describe()
to View Basic Statistical Details:stats = df.describe() print(stats)
Here's a breakdown of what describe()
returns:
By default, describe()
considers only the numeric columns.
If you have columns of type object
(like strings) and you want to see statistics on those as well:
data['D'] = ['apple', 'banana', 'cherry', 'apple', 'cherry'] df = pd.DataFrame(data) stats = df.describe(include='all') print(stats)
For object-type columns, here's what you get:
info()
to View General Information:The info()
method provides a concise summary of your DataFrame, including the non-null counts and data types:
print(df.info())
Apart from describe()
, there are individual methods to fetch specific statistics:
For example:
print("Mean of column A:", df['A'].mean()) print("Standard Deviation of column B:", df['B'].std())
Pandas makes it very convenient to obtain a statistical overview of your data. Using methods like describe()
, info()
, and other specific statistical methods, you can have an insightful understanding of your dataset in just a few lines of code.
Basic statistics in Pandas DataFrame:
describe()
method to get basic statistics for numerical columns.import pandas as pd data = {'Age': [25, 30, 28, 35, 32], 'Salary': [50000, 60000, 55000, 70000, 65000]} df = pd.DataFrame(data) basic_stats = df.describe()
Summary statistics in Pandas:
describe()
method.summary_stats = df.describe()
Viewing mean and median in Pandas DataFrame:
mean()
and median()
methods.mean_age = df['Age'].mean() median_salary = df['Salary'].median()
Pandas DataFrame statistics overview:
info()
method to get an overview of the DataFrame.df_info = df.info()
Exploring data with Pandas describe:
describe()
method.data_distribution = df.describe()
Statistical summary of Pandas DataFrame:
stats_summary = df.describe(include='all')
Calculate variance and standard deviation in Pandas:
variance_salary = df['Salary'].var() std_dev_age = df['Age'].std()
Overview of basic stats functions in Pandas:
mean()
, median()
, var()
, std()
, etc.mean_age = df['Age'].mean() median_salary = df['Salary'].median()
Pandas DataFrame info and statistics:
df_info = df.info() stats_summary = df.describe()