The info
function in Pandas is displays a summary of the dataframe. It displays column names, data types, the number of non-null values, and memory usage.
The syntax of the info
function is as follows:
DataFrame.info(verbose=None, buf=None, max_cols=None, memory_usage=None, show_counts=None, null_counts=None)
All parameters are optional for the info
function. Parameters and their descriptions are given below:
Parameters | Description |
---|---|
verbose |
Determines whether the full summary is to be printed. Takes a bool value. By default, the setting in pandas.options.display.max_info_columns is followed. |
buf |
Determines where to send the output. By default, the output is printed to sys.stdout . |
max_cols |
Determines when to switch from the verbose to the truncated output. Takes an int variable. If the dataframe has more than max_cols columns, the truncated output is used. By default, the setting in pandas.options.display.max_info_columns is used. |
memory_usage |
Determines whether total memory usage of the dataframe elements (including the index) should be displayed. By default, this follows the pandas.options.display.memory_usage setting. |
show_counts |
Determines whether to show non-null value counts or not. A value of True will always show the counts, while False never shows the counts. |
The info
function does not return anything. Instead, it outputs a concise summary of the dataframe.
The code snippet below shows how we can use the info
function in Pandas:
If
verbose = False
, column information is not printed.
memory_usage
can be altered while dealing with larger dataframes.
import pandas as pdimport numpy as np# Creating a dataframeint_values = [1, 2, 3, np.NAN, 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("Original Dataframe")print(df)print('\n')# With verbose = Trueprint(df.info(verbose=True))print('\n')# With verbose = Falseprint(df.info(verbose=False))print('\n')# Changing mempry usageprint(df.info(memory_usage='deep'))
Free Resources