Labs ICT
โญ Pro Login

DataFrame Attributes

Shape, columns, dtypes โ€” understanding your data.

2 min read | Pandas Tutorial
โญ

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

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.

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

๐Ÿงช Quick Quiz

What does df.shape return?