Python | Pandas dataframe.info ()

Python Methods and Functions

The Pandas dataframe.info() function is used to get a quick summary of the data. This is very useful when performing analytical data analysis. To get an overview of the dataset, we use the dataframe.info () function.

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.

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

Example # 1: Use the info () function to print a complete data summary.

# import pandas as pd

import pandas as pd

 
# Create a data frame

df = pd.read_csv ( "nba.csv" )

  
# Print the data frame
df

Let's write a complete data summary.

# print full summary
df.info ( )

Output:

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

Example # 2: Use the info () function to print a short summary of the data

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

# import pandas as pd

import pandas as pd

 
# Create data frame

df = pd.read_csv ( "nba.csv" )

 
# Print a summary
# dataframe by setting verbose = False

df.info (verbose = False )

Output:

Like us we see from the results, the summary is very clear and short. This is useful when we have thousands of attributes in a data frame.

Example # 3: Use the info () function to print a complete summary of the data and exclude null values.

Note. To print the full summary without regard to null values, we can use the null values ​​option and set it to false.

# import pandas as pd

import pandas as pd

 
# Create a data frame

df = pd.read_csv ( "nba.csv" )

 
# Print full summary of data
# with zero exclusion

df.info (verbose = True , null_counts = False )

Output:

As you can see from the output, the summary is complete, but null values ​​are excluded.





Get Solution for free from DataCamp guru