pandas dataframe info() function

Pandas – Get dataframe summary with info()

In this tutorial, we will look at how to use the info() method of a pandas dataframe to get its summary with the help of some examples.

pandas dataframe info() function

What does the info() function do in a pandas dataframe?

The pandas dataframe info() function is used to get a concise summary of a dataframe. It gives information such as the column dtypes, count of non-null values in each column, the memory usage of the dataframe, etc.

The following is the syntax –

df.info()

The info() function in pandas takes the following arguments.

  • verbose (bool, optional) – Determines whether to print the full summary or not. By default, the info() function, prints the summary of the total columns set under the pandas.options.display.max_info_columns attribute.
  • buf (writer buffer) – The writer buffer to send the output to. By default, the output is sent to sys.stdout. You can use this parameter to write the output of the info() to a file as well.
  • memory_usage (bool, str, optional) – Whether to display the total memory usage of the dataframe. By default, this follows the pandas.options.display.memory_usage setting.
  • show_counts (bool, optional) – Whether to show the count of non-null values in each column.

The info() function does not return any value (returns None) rather it prints the generated summary to the standard output (by default).

Examples

Let’s now look at some examples of using the info() function in Pandas.

Let’s create a Pandas dataframe that we will be using throughout this tutorial.

import numpy as np
import pandas as pd

# employee data
data = {
    "Name": ["Jim", "Dwight", "Angela", "Tobi"],
    "Age": [26, np.nan, 27, 32],
    "Department": ["Sales", "Sales", "Accounting", np.nan]
}

# create pandas dataframe
df = pd.DataFrame(data)

# display the dataframe
df

Output:

📚 Data Science Programs By Skill Level

Introductory

Intermediate ⭐⭐⭐

Advanced ⭐⭐⭐⭐⭐

🔎 Find Data Science Programs 👨‍💻 111,889 already enrolled

Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.

employee dataframe with some nan values

Here, we created a Pandas dataframe with some information about employees in an office. The dataframe has three columns – “Name”, “Age”, and “Department”. Notice that there are some NaN values as well present in the dataframe

Example 1 – Using the info() function with default parameters

Let’s apply the info() function to the above dataframe.

# get dataframe summary
df.info()

Output:

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

We get a summary of the dataframe. The summary includes the following information about the dataframe –

  • The class of the dataframe object.
  • The number of rows in the dataframe index.
  • The number of columns.
  • Details about each column – the dtype and the number of non-null values in the column.
  • Count of columns of each dtype.
  • The total memory usage of the dataframe.

Example 2 – Get a summary of all the columns with pandas info() function

If you’re working with a dataframe having a large number of columns (over 100), using the pandas dataframe info() function with the default parameters will only give the overall summary of the dataframe.

To demonstrate this, let’s first create a synthetic dataframe with 200 columns.

# create dataframe with 500 rows and 200 columns
arr = np.random.rand(500, 200)
df = pd.DataFrame(arr, columns=["Col"+str(i) for i in range(1, 201)])
# display the head of the dataframe
df.head()

Here, we created a dataframe with 500 rows and 200 columns.

dataframe with 200 columns

Let’s now get the dataframe summary using the info() function with its default parameters.

# show dataframe summary
df.info()

Output:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 500 entries, 0 to 499
Columns: 200 entries, Col1 to Col200
dtypes: float64(200)
memory usage: 781.4 KB

You can see that we only get an overall summary of the dataframe and do not get a column-level summary (summary for each column) as we did in the previous example.

To get the column-level summary for each column in a dataframe (with a large number of columns). Pass the following arguments.

  • verbose=True – This will show column-level information like the column name, column dtype, etc.
  • show_counts=True – This will show the count of non-null values in each column.

Let’s pass both these arguments to the info() function.

# dataframe summary to include details about each column
df.info(verbose=True, show_counts=True)

Output:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 500 entries, 0 to 499
Data columns (total 200 columns):
 #    Column  Non-Null Count  Dtype  
---   ------  --------------  -----  
 0    Col1    500 non-null    float64
 1    Col2    500 non-null    float64
 2    Col3    500 non-null    float64
 3    Col4    500 non-null    float64
 4    Col5    500 non-null    float64
 5    Col6    500 non-null    float64
 6    Col7    500 non-null    float64
 7    Col8    500 non-null    float64
 8    Col9    500 non-null    float64
 9    Col10   500 non-null    float64
 10   Col11   500 non-null    float64
 11   Col12   500 non-null    float64
 12   Col13   500 non-null    float64
 13   Col14   500 non-null    float64
 14   Col15   500 non-null    float64
 15   Col16   500 non-null    float64
 16   Col17   500 non-null    float64
 17   Col18   500 non-null    float64
 18   Col19   500 non-null    float64
 19   Col20   500 non-null    float64
 20   Col21   500 non-null    float64
 21   Col22   500 non-null    float64
 22   Col23   500 non-null    float64
 23   Col24   500 non-null    float64
 24   Col25   500 non-null    float64
 25   Col26   500 non-null    float64
 26   Col27   500 non-null    float64
 27   Col28   500 non-null    float64
 28   Col29   500 non-null    float64
 29   Col30   500 non-null    float64
 30   Col31   500 non-null    float64
 31   Col32   500 non-null    float64
 32   Col33   500 non-null    float64
 33   Col34   500 non-null    float64
 34   Col35   500 non-null    float64
 35   Col36   500 non-null    float64
 36   Col37   500 non-null    float64
 37   Col38   500 non-null    float64
 38   Col39   500 non-null    float64
 39   Col40   500 non-null    float64
 40   Col41   500 non-null    float64
 41   Col42   500 non-null    float64
 42   Col43   500 non-null    float64
 43   Col44   500 non-null    float64
 44   Col45   500 non-null    float64
 45   Col46   500 non-null    float64
 46   Col47   500 non-null    float64
 47   Col48   500 non-null    float64
 48   Col49   500 non-null    float64
 49   Col50   500 non-null    float64
 50   Col51   500 non-null    float64
 51   Col52   500 non-null    float64
 52   Col53   500 non-null    float64
 53   Col54   500 non-null    float64
 54   Col55   500 non-null    float64
 55   Col56   500 non-null    float64
 56   Col57   500 non-null    float64
 57   Col58   500 non-null    float64
 58   Col59   500 non-null    float64
 59   Col60   500 non-null    float64
 60   Col61   500 non-null    float64
 61   Col62   500 non-null    float64
 62   Col63   500 non-null    float64
 63   Col64   500 non-null    float64
 64   Col65   500 non-null    float64
 65   Col66   500 non-null    float64
 66   Col67   500 non-null    float64
 67   Col68   500 non-null    float64
 68   Col69   500 non-null    float64
 69   Col70   500 non-null    float64
 70   Col71   500 non-null    float64
 71   Col72   500 non-null    float64
 72   Col73   500 non-null    float64
 73   Col74   500 non-null    float64
 74   Col75   500 non-null    float64
 75   Col76   500 non-null    float64
 76   Col77   500 non-null    float64
 77   Col78   500 non-null    float64
 78   Col79   500 non-null    float64
 79   Col80   500 non-null    float64
 80   Col81   500 non-null    float64
 81   Col82   500 non-null    float64
 82   Col83   500 non-null    float64
 83   Col84   500 non-null    float64
 84   Col85   500 non-null    float64
 85   Col86   500 non-null    float64
 86   Col87   500 non-null    float64
 87   Col88   500 non-null    float64
 88   Col89   500 non-null    float64
 89   Col90   500 non-null    float64
 90   Col91   500 non-null    float64
 91   Col92   500 non-null    float64
 92   Col93   500 non-null    float64
 93   Col94   500 non-null    float64
 94   Col95   500 non-null    float64
 95   Col96   500 non-null    float64
 96   Col97   500 non-null    float64
 97   Col98   500 non-null    float64
 98   Col99   500 non-null    float64
 99   Col100  500 non-null    float64
 100  Col101  500 non-null    float64
 101  Col102  500 non-null    float64
 102  Col103  500 non-null    float64
 103  Col104  500 non-null    float64
 104  Col105  500 non-null    float64
 105  Col106  500 non-null    float64
 106  Col107  500 non-null    float64
 107  Col108  500 non-null    float64
 108  Col109  500 non-null    float64
 109  Col110  500 non-null    float64
 110  Col111  500 non-null    float64
 111  Col112  500 non-null    float64
 112  Col113  500 non-null    float64
 113  Col114  500 non-null    float64
 114  Col115  500 non-null    float64
 115  Col116  500 non-null    float64
 116  Col117  500 non-null    float64
 117  Col118  500 non-null    float64
 118  Col119  500 non-null    float64
 119  Col120  500 non-null    float64
 120  Col121  500 non-null    float64
 121  Col122  500 non-null    float64
 122  Col123  500 non-null    float64
 123  Col124  500 non-null    float64
 124  Col125  500 non-null    float64
 125  Col126  500 non-null    float64
 126  Col127  500 non-null    float64
 127  Col128  500 non-null    float64
 128  Col129  500 non-null    float64
 129  Col130  500 non-null    float64
 130  Col131  500 non-null    float64
 131  Col132  500 non-null    float64
 132  Col133  500 non-null    float64
 133  Col134  500 non-null    float64
 134  Col135  500 non-null    float64
 135  Col136  500 non-null    float64
 136  Col137  500 non-null    float64
 137  Col138  500 non-null    float64
 138  Col139  500 non-null    float64
 139  Col140  500 non-null    float64
 140  Col141  500 non-null    float64
 141  Col142  500 non-null    float64
 142  Col143  500 non-null    float64
 143  Col144  500 non-null    float64
 144  Col145  500 non-null    float64
 145  Col146  500 non-null    float64
 146  Col147  500 non-null    float64
 147  Col148  500 non-null    float64
 148  Col149  500 non-null    float64
 149  Col150  500 non-null    float64
 150  Col151  500 non-null    float64
 151  Col152  500 non-null    float64
 152  Col153  500 non-null    float64
 153  Col154  500 non-null    float64
 154  Col155  500 non-null    float64
 155  Col156  500 non-null    float64
 156  Col157  500 non-null    float64
 157  Col158  500 non-null    float64
 158  Col159  500 non-null    float64
 159  Col160  500 non-null    float64
 160  Col161  500 non-null    float64
 161  Col162  500 non-null    float64
 162  Col163  500 non-null    float64
 163  Col164  500 non-null    float64
 164  Col165  500 non-null    float64
 165  Col166  500 non-null    float64
 166  Col167  500 non-null    float64
 167  Col168  500 non-null    float64
 168  Col169  500 non-null    float64
 169  Col170  500 non-null    float64
 170  Col171  500 non-null    float64
 171  Col172  500 non-null    float64
 172  Col173  500 non-null    float64
 173  Col174  500 non-null    float64
 174  Col175  500 non-null    float64
 175  Col176  500 non-null    float64
 176  Col177  500 non-null    float64
 177  Col178  500 non-null    float64
 178  Col179  500 non-null    float64
 179  Col180  500 non-null    float64
 180  Col181  500 non-null    float64
 181  Col182  500 non-null    float64
 182  Col183  500 non-null    float64
 183  Col184  500 non-null    float64
 184  Col185  500 non-null    float64
 185  Col186  500 non-null    float64
 186  Col187  500 non-null    float64
 187  Col188  500 non-null    float64
 188  Col189  500 non-null    float64
 189  Col190  500 non-null    float64
 190  Col191  500 non-null    float64
 191  Col192  500 non-null    float64
 192  Col193  500 non-null    float64
 193  Col194  500 non-null    float64
 194  Col195  500 non-null    float64
 195  Col196  500 non-null    float64
 196  Col197  500 non-null    float64
 197  Col198  500 non-null    float64
 198  Col199  500 non-null    float64
 199  Col200  500 non-null    float64
dtypes: float64(200)
memory usage: 781.4 KB

We get a detailed summary for each column in the dataframe.

Summary

In this tutorial, we looked at how to use the info() function in pandas to the dataframe summary. The following are the key takeaways –

  • The info() function prints the dataframe summary with information like the number of rows, number of columns, column dtypes, and the count of non-null values in each column, etc. It also shows the memory usage of the entire dataframe.
  • For dataframes with a large number of columns, the info() function (with its default parameters) only prints an overall summary of the dataframe. Pass verbose=True and show_counts=True for a more detailed column-level summary.

You might also be interested in –


Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.


Author

  • Piyush Raj

    Piyush is a data professional passionate about using data to understand things better and make informed decisions. He has experience working as a Data Scientist in the consulting domain and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.

Scroll to Top