Skip to main content
Albero Academy

The DataFrame

A labelled 2-D table — the object you will use 95% of the time.

Foundations9 min

A DataFrame is a 2-D table: a collection of Series columns sharing one index. It's the object you'll use almost all the time — rows are records, columns are fields, each column has its own dtype.

Creating a DataFrame

from a dict of columns
df = pd.DataFrame({
"name": ["Aanya", "Rohan", "Priya"],
"programme": ["Data", "Full Stack", "Data"],
"package": [6.5, 8.0, 7.25],
})
df

Anatomy

  • index — the row labels (0, 1, 2… by default).
  • columns — the named fields, each a Series with its own dtype.
  • values — the underlying 2-D NumPy data.
accessing the parts
df.index # the row labels
df.columns # Index(['name', 'programme', 'package'])
df["package"] # one column → a Series
df.dtypes # the type of each column

Key takeaways

  1. 01A DataFrame is a 2-D labelled table: columns (Series) sharing one index.
  2. 02Rows are records, columns are named fields, each column has its own dtype.
  3. 03Access parts via .index, .columns, .dtypes and df["col"].
  4. 04Most operations return a new DataFrame — chain them; the original is unchanged.

Finished this chapter?

Mark it complete to track your progress through Pandas.