Pandas DataFrame Info Method

PythonPythonBeginner
Practice Now

Introduction

The info() method in the Python Pandas library is used to get a summary of a DataFrame. It provides valuable information about the DataFrame including the index dtype and columns, non-null values, and memory usage.

VM Tips

After the VM startup is done, click the top left corner to switch to the Notebook tab to access Jupyter Notebook for practice.

Sometimes, you may need to wait a few seconds for Jupyter Notebook to finish loading. The validation of operations cannot be automated because of limitations in Jupyter Notebook.

If you face issues during learning, feel free to ask Labby. Provide feedback after the session, and we will promptly resolve the problem for you.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL pandas(("`Pandas`")) -.-> pandas/DataSelectionGroup(["`Data Selection`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/DataScienceandMachineLearningGroup(["`Data Science and Machine Learning`"]) pandas/DataSelectionGroup -.-> pandas/select_columns("`Select Columns`") python/DataStructuresGroup -.-> python/lists("`Lists`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/DataStructuresGroup -.-> python/dictionaries("`Dictionaries`") python/ModulesandPackagesGroup -.-> python/importing_modules("`Importing Modules`") python/DataScienceandMachineLearningGroup -.-> python/numerical_computing("`Numerical Computing`") python/DataScienceandMachineLearningGroup -.-> python/data_analysis("`Data Analysis`") subgraph Lab Skills pandas/select_columns -.-> lab-68636{{"`Pandas DataFrame Info Method`"}} python/lists -.-> lab-68636{{"`Pandas DataFrame Info Method`"}} python/tuples -.-> lab-68636{{"`Pandas DataFrame Info Method`"}} python/dictionaries -.-> lab-68636{{"`Pandas DataFrame Info Method`"}} python/importing_modules -.-> lab-68636{{"`Pandas DataFrame Info Method`"}} python/numerical_computing -.-> lab-68636{{"`Pandas DataFrame Info Method`"}} python/data_analysis -.-> lab-68636{{"`Pandas DataFrame Info Method`"}} end

Import the necessary libraries

First, we need to import the pandas library, which is a powerful data manipulation library in Python.

import pandas as pd

Create a DataFrame

Next, we need to create a DataFrame. We can do this by using the pd.DataFrame() function and passing in a dictionary of data.

int_values = [1, 2, 3, 4, 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})

Use the info() method

Now that we have our DataFrame, we can use the info() method to get the summary information. By default, the info() method prints the full summary of the DataFrame.

df.info()

Analyze the output

After running the code, you will see the summary information about the DataFrame, including the data type of each column, the number of non-null values, and the memory usage. Here's an example output:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 3 columns):
 ##   Column    Non-Null Count  Dtype
---  ------    --------------  -----
 0   int_col   5 non-null      int64
 1   text_col  5 non-null      object
 2   float_col 5 non-null      float64
dtypes: float64(1), int64(1), object(1)
memory usage: 248.0+ bytes

Summary

The info() method in the Python Pandas library is a useful method to get a quick summary of a DataFrame. It provides information about the index dtype and columns, non-null values, and memory usage. By default, it displays the full summary, but you can also modify the parameters to customize the output. This method is helpful for understanding the structure of the DataFrame, especially when dealing with large datasets. With the information obtained from info(), you can make informed decisions about data cleaning, manipulation, and analysis.

Other Python Tutorials you may like