How to Print Information of Pandas DataFrame?
Print Information of a Pandas DataFrame
To print information of Pandas DataFrame, call DataFrame.info() method. The DataFrame.info() method returns nothing but just prints information about this DataFrame.
Syntax
The syntax to use info() method of a DataFrame is
DataFrame.info(verbose=None, buf=None, max_cols=None, memory_usage=None, show_counts=None, null_counts=None)
Examples
1. Print DataFrame information
In the following program, we have created a DataFrame. We shall print this DataFrame's information using DataFrame.info() method.
Python Program
import pandas as pd
df = pd.DataFrame(
[['abc', 22],
['xyz', 25],
['pqr', 31]],
columns=['name', 'age'])
df.info()
Output
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
name 3 non-null object
age 3 non-null int64
dtypes: int64(1), object(1)
memory usage: 128.0+ bytes
If we observe, info() method printed the type of this object, range, columns, number of entries in each columns, if the columns are non-null, datatype of columns, and memory usage of this DataFrame.
Summary
In this tutorial of Python Examples, we learned how to print the information of a DataFrame using DataFrame.info() method.