LambdaLab
Informatics Practices · Class 12 · Python Pandas · DataFrame
PandasDataFrame⏱️ 6 min read

DataFrame Attributes

Just like a Series, a DataFrame carries built-in attributes that describe it — its labels, its shape, its types and more. They're facts about the table, so you read them without brackets.

1Click through the attributes

Here's a small DataFrame df. Click any attribute to see what it returns.

DataFrame attribute inspector

Attributes describe a DataFrame (no brackets — they aren't functions). Click one to see what it returns.

Name
English
IP
Maths
ID 1
Rinku658972
ID 2
Ritu778369
ID 3
Pankaj729587
DataFrame: df
# (rows, columns)
df.shape
(3, 4)

2The attributes at a glance

  • index — the row labels.
  • columns — the column labels.
  • axes — a list of both axes: the index and the columns.
  • dtypes — the dtype of each column (they can differ!).
  • shape — a (rows, columns) tuple.
  • size — total number of cells (rows × columns).
  • ndim — number of dimensions; always 2.
  • values — the data as a NumPy array.
  • emptyTrue if the DataFrame has no data.
  • T — the transpose (rows become columns and vice-versa).

3See them all at once

df_attributes.py
Watch Out
Attributes take no brackets: it's df.shape, not df.shape(). Notice df.dtypes lists a type per column— that's the big difference from a Series, which has just one dtype.
Quick Check

For a DataFrame with 4 rows and 3 columns, what is df.shape and df.size?

Quick Check

Which attribute can return DIFFERENT types for different columns?