Labs ICT
Pro Login

DataFrame Attributes

Shape, columns, dtypes — understanding your data.

DataFrame Attributes

Before you start manipulating data, you need to understand what you're working with. DataFrame attributes give you a quick overview without digging through the entire dataset.

shape — How Big Is This Thing?

The `shape` attribute tells you the dimensions of your DataFrame — rows and columns:


import pandas as pd

data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Age': [25, 30, 35]}
df = pd.DataFrame(data)

print(df.shape)
    

This returns `(3, 2)` — 3 rows and 2 columns. Think of it like checking the size of a spreadsheet before you start working.

columns and dtypes

Want to know what columns you have and what type of data they contain?


print(df.columns)
print(df.dtypes)
    

`columns` gives you the column names. `dtypes` shows you the data type of each column — integers, floats, objects (strings), etc. One thing that confused me at first was why strings show as "object" instead of "string". It's just a Pandas quirk — don't worry about it.

values and index

Need the raw data or the row labels?


print(df.values)
print(df.index)
    

`values` gives you a NumPy array of the actual data. `index` shows you the row labels. These are less commonly used, but good to know they exist.

Try it Yourself →

Key Takeaways

  • `shape` returns (rows, columns) as a tuple
  • `columns` lists all column names
  • `dtypes` shows the data type of each column
  • `values` returns a NumPy array of the data