Open In App

Python | Pandas dataframe.info()

Improve
Improve
Like Article
Like
Save
Share
Report

The `dataframe.info()` function in Pandas proves to be an invaluable tool for obtaining a succinct summary of a dataframe. This function is particularly useful during exploratory analysis, offering a quick and informative overview of the dataset. Leveraging `dataframe.info()` is an efficient way to gain insights into the structure and characteristics of the data, making it an essential step in the data analysis workflow.

Pandas dataframe.info() Syntax

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

Parameters: 

  • verbose : Whether to print the full summary. None follows the display.max_info_columns setting. True or False overrides the display.max_info_columns setting. 
  • buf : writable buffer, defaults to sys.stdout 
  • max_cols : Determines whether full summary or short summary is printed. None follows the display.max_info_columns setting. 
  • memory_usage : Specifies whether total memory usage of the DataFrame elements (including index) should be displayed. None follows the display.memory_usage setting. True or False overrides the display.memory_usage setting. A value of ‘deep’ is equivalent of True, with deep introspection. Memory usage is shown in human-readable units (base-2 representation).
  • null_counts : Whether to show the non-null counts. If None, then only show if the frame is smaller than max_info_rows and max_info_columns. If True, always show counts. If False, never show counts.

For link to the CSV file used in the code, click here

What is dataframe.info() Function in Pandas ?

The `DataFrame.info()` function in Pandas is a method used to obtain a concise summary of a DataFrame’s structure and information. When called on a Pandas DataFrame, it provides essential details such as the total number of non-null values, data types of each column, and memory usage. This summary is beneficial for quickly assessing the completeness of the dataset, identifying potential missing values, and understanding the overall data types present in the DataFrame.

Pandas dataframe.info() Examples

There are some examples of dataframe.info() examples those shown the advantages uses of the dataframe.info() function. those are following.

Printing the summary of a DataFram using Pandas info() Function 

In this example code utilizes the pandas library to work with tabular data in Python. It imports the library as ‘pd’ and reads a CSV file named “nba.csv” into a DataFrame (df). Finally, it prints the contents of the DataFrame, displaying the structured representation of the data from the CSV file.

Python3




# importing pandas as pd
import pandas as pd
 
# Creating the dataframe
df = pd.read_csv("nba.csv")
 
# Print the dataframe
df


Output :

second-print-

Print the Full Summary of the Dataframe

In below example code uses the `info()` method on a DataFrame named `df` to display a concise summary of its structure.

Python3




# to print the full summary
df.info()


Output : 

final-reviewAs we can see in the output, the summary includes list of all columns with their data types and the number of non-null values in each column. we also have the value of rangeindex provided for the index axis. 

Summarize a DataFrame in Pandas use info() Function

Note : In order to print the short summary, we can use the verbose parameter and set it to False.

In this example code utilizes the Pandas library to handle tabular data. It imports the library as ‘pd’ and reads a CSV file named “nba.csv” into a Pandas DataFrame called ‘df’. The last line prints a concise summary of the DataFrame, excluding verbose details, using the `info()` function with the parameter ‘verbose’ set to False. This summary includes information about the columns, data types, and memory usage.

Python3




# importing pandas as pd
import pandas as pd
 
# Creating the dataframe
df = pd.read_csv("nba.csv")
 
# Print the short summary of the
# dataframe by setting verbose = False
df.info(verbose = False)


Output : 

As, we can see in the output, the summary is very crisp and short. It is helpful when we have 1000s of attributes in dataframe. 

Use info() Function to Print a Full Summary of the Dataframe and Exclude the Null-Counts

Note : In order to print the full summary, with null-counts excluded, we can use null-counts parameter and set it to be false.

In this example code uses the pandas library in Python to read a CSV file named “nba.csv” into a DataFrame called ‘df.’ The last line prints a concise summary of the DataFrame, including information about its structure, data types, and non-null counts for each column, with null counts excluded.

Python3




# importing pandas as pd
import pandas as pd
 
# Creating the dataframe
df = pd.read_csv("nba.csv")
 
# Print the full summary of the dataframe
# with null count excluded
df.info(verbose = True, null_counts = False)


Output : 

As, we can see in the output, the summary is full but null-counts are excluded.



Last Updated : 18 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads