+5 votes
in Programming Languages by (77.2k points)
Is there any function to display the basic information about a pandas DataFrame, e.g., number of rows/columns, data types, memory usage, etc.?

1 Answer

+2 votes
by (354k points)
selected by
 
Best answer

You can use the info() function of pandas to print information about a pandas DataFrame. The function does not return anything; it will just show the index dtype and columns, non-null values, and memory usage. You can find more details in the link given under info().

Here is an example:

>>> import pandas as pd
>>> df = pd.DataFrame({'a':np.random.random(3), 'b':np.random.random(3), 'c':np.random.random(3)})
>>> df
          a         b         c
0  0.227895  0.360818  0.928633
1  0.358838  0.054035  0.840515
2  0.113202  0.784529  0.015492
>>> df.info(verbose=True)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype  
---  ------  --------------  -----  
 0   a       3 non-null      float64
 1   b       3 non-null      float64
 2   c       3 non-null      float64
dtypes: float64(3)
memory usage: 200.0 bytes


...