Signup/Sign In

Pandas DataFrame info() Method

In this tutorial, we will discuss and learn the Python pandas DataFrame.info() method. This method can be used to get the summary of a DataFrame. When we apply this method on the DataFrame, it prints information about a DataFrame including the index dtype and columns, non-null values, and memory usage.

The below is the syntax of the DataFrame.info() method.

Syntax

DataFrame.info(verbose=None, buf=None, max_cols=None, memory_usage=None, show_counts=None, null_counts=None)

Some of the important parameters of the DataFrame.info() method are,

data: It represents the DataFrame, prints information about it.

verbose: It represents the bool(True or False), which is optional. It indicates whether to print the full summary of the DataFrame or not.

memory_usage: It represents the bool(True or False), which is optional. It specifies whether to display information about the total memory usage of the DataFrame elements that includes the index

show_counts: It represents the bool(True or False), which is optional. It indicates whether to display the non-null counts.

null_counts: It represents the bool(True or False), which is optional.

Example: The DataFrame.info() Method

The DataFrame.info() method prints the full summary of the DataFrame. See, how this works in the below example.

import pandas as pd
int_values = [1, 2, 3, 4, 5]
text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
float_values = [0.0, 0.25, 0.5, 0.75, 1.0]
df = pd.DataFrame({"int_col": int_values, "text_col": text_values,"float_col": float_values})
print("----SUMMARY OF THE DATAFRAME IS-----")
print(df.info(verbose=True))


----SUMMARY OF THE DATAFRAME IS-----
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 int_col 5 non-null int64
1 text_col 5 non-null object
2 float_col 5 non-null float64
dtypes: float64(1), int64(1), object(1)
memory usage: 248.0+ bytes
None

Example: Set verbose=False in the DataFrame.info() Method

Here, we are printing a summary of columns count and their dtypes but not per column information. See the below example.

import pandas as pd
int_values = [1, 2, 3, 4, 5]
text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
float_values = [0.0, 0.25, 0.5, 0.75, 1.0]
df = pd.DataFrame({"int_col": int_values, "text_col": text_values,"float_col": float_values})
print("----SUMMARY OF THE DATAFRAME IS-----")
print(df.info(verbose=False))


----SUMMARY OF THE DATAFRAME IS-----
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Columns: 3 entries, int_col to float_col
dtypes: float64(1), int64(1), object(1)
memory usage: 248.0+ bytes
None

Example: The DataFrame.info() Method

When we set parameter null_counts=False,the DataFrame.info() method prints the full summary of the DataFrame by excluding the null counts. See the below example.

import pandas as pd
import numpy as np
int_values = [np.nan,np.nan,np.nan,np.nan,np.nan]
text_values = ['alpha', 'beta', 'gamma','delta', 'epsilon']
float_values = [0.0, 0.25, 0.5, 0.75, 1.0]
df = pd.DataFrame({"int_col": int_values, "text_col": text_values,"float_col": float_values})
print("----SUMMARY OF THE DATAFRAME IS-----")
print(df.info(verbose=True,null_counts = False))


----SUMMARY OF THE DATAFRAME IS-----
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 3 columns):
# Column Dtype
--- ------ -----
0 int_col float64
1 text_col object
2 float_col float64
dtypes: float64(2), object(1)
memory usage: 248.0+ bytes
None

Conclusion

In this tutorial, we learned the Python pandas DataFrame.info() method. We learned the syntax and by applying this method on the DataFrame with some examples.



About the author:
I like writing about Python, and frameworks like Pandas, Numpy, Scikit, etc. I am still learning Python. I like sharing what I learn with others through my content.