Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
pandas

What is info function in Pandas?

Hassaan Waqar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

Syntax

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)

Parameters

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.

Return value

The info function does not return anything. Instead, it outputs a concise summary of the dataframe.

Examples

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 pd
import numpy as np
# Creating a dataframe
int_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 = True
print(df.info(verbose=True))
print('\n')
# With verbose = False
print(df.info(verbose=False))
print('\n')
# Changing mempry usage
print(df.info(memory_usage='deep'))

RELATED TAGS

python
pandas

CONTRIBUTOR

Hassaan Waqar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring