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 :
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 :
As 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.
Python | Pandas dataframe.info()
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.