0
0
PandasHow-ToBeginner · 3 min read

How to Use info() in pandas to Inspect DataFrames

Use the info() method on a pandas DataFrame to get a concise summary of its structure, including the number of rows, columns, data types, and non-null counts. This helps you quickly understand your data's shape and missing values.
📐

Syntax

The basic syntax of info() is simple and used directly on a DataFrame object.

  • DataFrame.info(verbose=None, buf=None, max_cols=None, memory_usage=None, show_counts=None)

Key parts explained:

  • verbose: If True, shows full summary; if False, shows only summary info.
  • buf: Where to send the output (default is console).
  • max_cols: Max columns to show in summary.
  • memory_usage: Whether to show memory usage.
  • show_counts: Whether to show non-null counts.
python
DataFrame.info(verbose=None, buf=None, max_cols=None, memory_usage=None, show_counts=None)
💻

Example

This example shows how to use info() on a simple DataFrame to see its structure and missing data.

python
import pandas as pd

data = {'Name': ['Alice', 'Bob', 'Charlie', None],
        'Age': [25, 30, None, 22],
        'City': ['New York', 'Los Angeles', 'Chicago', 'Houston']}

df = pd.DataFrame(data)

# Use info() to get 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 3 non-null object 1 Age 3 non-null float64 2 City 4 non-null object memory usage: 224.0+ bytes
⚠️

Common Pitfalls

Some common mistakes when using info() include:

  • Expecting info() to return a value; it prints output and returns None.
  • Not noticing that missing values show as fewer non-null counts.
  • Using verbose=False and missing important details.

Always check the printed output carefully.

python
import pandas as pd

data = {'A': [1, 2, None], 'B': [4, None, 6]}
df = pd.DataFrame(data)

# Wrong: expecting info() to return data
info_data = df.info()
print(f"Returned value: {info_data}")  # This prints None

# Right: just call info() to see summary
df.info()
Output
Returned value: None <class 'pandas.core.frame.DataFrame'> RangeIndex: 3 entries, 0 to 2 Data columns (total 2 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 A 2 non-null float64 1 B 2 non-null float64 memory usage: 176.0 bytes
📊

Quick Reference

Summary of info() usage tips:

  • Call df.info() to print DataFrame summary.
  • Use verbose=True to see all columns if many exist.
  • Check Non-Null Count to find missing data.
  • Use memory_usage='deep' to see detailed memory use.

Key Takeaways

Use df.info() to quickly see DataFrame structure and missing values.
info() prints output and returns None, so don't assign it to variables expecting data.
Check non-null counts in info() output to identify missing data.
Use verbose=True to see full details for large DataFrames.
memory_usage='deep' shows detailed memory usage if needed.