Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
int_values = [1, 2, 3, 4]
text_values = ['alpha', 'beta', 'gamma', 'delta']
float_values = [0.0, 0.35, 2.5, 0.85]
df = pd.DataFrame({"int_cl": int_values, "text_cl": text_values,
                   "float_cl": float_values})
df
Out[2]:
int_cl text_cl float_cl
0 1 alpha 0.00
1 2 beta 0.35
2 3 gamma 2.50
3 4 delta 0.85

Prints information of all columns:

In [3]:
df.info(verbose=True)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4 entries, 0 to 3
Data columns (total 3 columns):
int_cl      4 non-null int64
text_cl     4 non-null object
float_cl    4 non-null float64
dtypes: float64(1), int64(1), object(1)
memory usage: 176.0+ bytes

Prints a summary of columns count and its dtypes but not per column information:

In [4]:
df.info(verbose=False)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4 entries, 0 to 3
Columns: 3 entries, int_cl to float_cl
dtypes: float64(1), int64(1), object(1)
memory usage: 176.0+ bytes

Pipe output of DataFrame.info to buffer instead of sys.stdout, get buffer content
and writes to a text file:

In [5]:
import io
buffer = io.StringIO()
df.info(buf=buffer)
s = buffer.getvalue()
with open("df_info.txt", "w",
          encoding="utf-8") as f:  # doctest: +SKIP
     f.write(s)
260        
Out[5]:
260

The memory_usage parameter allows deep introspection mode, specially useful for big
DataFrames and fine-tune memory optimization:

In [6]:
random_strings_array = np.random.choice(['p', 'q', 'r'], 10 ** 4)
df = pd.DataFrame({
     'column_1': np.random.choice(['p', 'q', 'r'], 10 ** 4),
     'column_2': np.random.choice(['p', 'q', 'r'], 10 ** 4),
     'column_3': np.random.choice(['p', 'q', 'r'], 10 ** 4)
})
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10000 entries, 0 to 9999
Data columns (total 3 columns):
column_1    10000 non-null object
column_2    10000 non-null object
column_3    10000 non-null object
dtypes: object(3)
memory usage: 234.5+ KB
In [7]:
df.info(memory_usage='deep')
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10000 entries, 0 to 9999
Data columns (total 3 columns):
column_1    10000 non-null object
column_2    10000 non-null object
column_3    10000 non-null object
dtypes: object(3)
memory usage: 1.8 MB