🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEpandas

pandas Documentation

LOADING ENGINE...

df.info()

AI & DATA SCIENCE // df-info

df.info() prints a concise technical summary of a DataFrame — its shape, column names, non-null counts per column, dtypes, and total memory usage — directly to the console.

Syntax

df.info(verbose=True, memory_usage=True)

Deep Dive Course

Unlike most DataFrame methods, info() doesn't return a value you'd assign to a variable — it prints its summary directly and returns None, so it's meant to be called on its own line purely for its side effect of displaying diagnostic information. The non-null count per column is one of its most useful pieces of information: comparing it against the DataFrame's total row count immediately reveals which columns have missing data, without needing a separate isna().sum() call.

1Understanding df.info()

Unlike most DataFrame methods, info() doesn't return a value you'd assign to a variable — it prints its summary directly and returns None, so it's meant to be called on its own line purely for its side effect of displaying diagnostic information. The non-null count per column is one of its most useful pieces of information: comparing it against the DataFrame's total row count immediately reveals which columns have missing data, without needing a separate isna().sum() call.

💡

df.info() returns None — don't try to assign its result to a variable or otherwise use it programmatically; it's meant purely for the side effect of printing a summary to the console.

editor.html
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, 2, np.nan], "b": ["x", "y", "z"]})
df.info()
localhost:3000

2Practical Example

Here is a real-world application of df.info() showing how it is used in production Pandas code.

editor.html
import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3]})
result = df.info()
print(result)
localhost:3000

3Best Practices

Follow these guidelines when working with df.info():

1. Call df.info() right after loading a dataset, alongside head(), to quickly see dtypes and spot columns with missing data

2. Compare info()'s non-null counts per column against the total row count to spot missing data at a glance, without a separate isna() call

3. Pass memory_usage='deep' for a more accurate memory estimate specifically when the DataFrame has object-dtype columns, like strings, whose true memory use info()'s default shallow estimate can understate

⚠️

Tip: df.info() returns None — don't try to assign its result to a variable or otherwise use it programmatically; it's meant purely for the side effect of printing a summary to the console.

editor.html
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, 2, np.nan], "b": ["x", "y", "z"]})
df.info()
localhost:3000

Examples

Example 01Basic Usage
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, 2, np.nan], "b": ["x", "y", "z"]})
df.info()
Example 02Advanced Example
import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3]})
result = df.info()
print(result)

Best Practices

  • Call df.info() right after loading a dataset, alongside head(), to quickly see dtypes and spot columns with missing data
  • Compare info()'s non-null counts per column against the total row count to spot missing data at a glance, without a separate isna() call
  • Pass memory_usage='deep' for a more accurate memory estimate specifically when the DataFrame has object-dtype columns, like strings, whose true memory use info()'s default shallow estimate can understate

Interview Question

Why does printing the return value of df.info() show 'None' at the end of the output?

Hint: Think about what info() actually returns versus what it does as a side effect.

info() is designed to print its summary directly to the console as a side effect and doesn't return that summary as a usable value — its actual return value is None, matching the convention many display/print-oriented methods follow. Assigning its result to a variable and printing that variable separately shows the summary from the call to info() itself, followed by 'None' from printing its actual return value, which is a common point of confusion for people expecting info() to work like a method that returns the summary as a string.

Exercises

MediumPractice using df.info() in a real scenario.
View Solution
import pandas as pd
import numpy as np

df = pd.DataFrame({"a": [1, 2, np.nan], "b": ["x", "y", "z"]})
df.info()

Frequently Asked Questions

Why does printing the return value of df.info() show 'None' at the end of the output?

info() is designed to print its summary directly to the console as a side effect and doesn't return that summary as a usable value — its actual return value is None, matching the convention many display/print-oriented methods follow. Assigning its result to a variable and printing that variable separately shows the summary from the call to info() itself, followed by 'None' from printing its actual return value, which is a common point of confusion for people expecting info() to work like a method that returns the summary as a string.

Related Functions

df-describedf-dtypesdf-shape