pandas DataFrame for Beginners — Series vs DataFrame, head and info
Read this guide in: English · मराठी · हिंदी
A Series is one labelled column. A DataFrame is a full table. In pandas you build or load a DataFrame, then use head() and info() before any fancy work. Tiny check: Mumbai 120 + Pune 70 = 190.
Chala mitrano! Lists feel fine until you have ten columns. Today Series vs DataFrame with a shop sales table. Short sentences. Real numbers. Samajla ka?
Quick answer
Vertical starter path:
import pandas as pd- Build a DataFrame from a dict of lists (or read a CSV later).
df.head()— peek at rows.df.info()— types and nulls.df["sales"]is a Series.df["sales"].sum()— confirm 190 on the tiny example.
dict/lists → DataFrame → head → info → Series math
Language: English · मराठी · हिंदी
What do I need before this guide?
- Python + pandas in a Jupyter notebook (see the install guide).
- Comfort with a Python dict and list.
- Course: Series and DataFrame.
Before and after (look at the tables first)
Before — shop cities live in loose Python lists.
After — one DataFrame; sales.sum() = 190.
Before: loose lists. After: one DataFrame whose sales sum to 190.
Why DataFrame (not only lists)?
What a DataFrame gives you
- Column names you can trust.
- One place for many rows.
- Ready tools: filter, groupby, missing-value checks.
Why you care
- Shop exports, Instagram-like engagement dumps and Infosys client sheets all arrive as tables.
- Interviewers expect
head/infomuscle memory.
Build a tiny shop DataFrame
import pandas as pd
df = pd.DataFrame({
"city": ["Mumbai", "Pune"],
"sales": [120, 70],
})
df.head()
What you see:
- Two rows.
- Columns
cityandsales. - A default index 0, 1.
What it means: pandas wrapped your lists into a table.
Series vs DataFrame (plain words)
- Series — one column with an index. Example:
df["sales"]. - DataFrame — several columns side by side. Example:
df. - Selecting one column returns a Series; selecting two returns a DataFrame.
s = df["sales"] # Series
both = df[["city", "sales"]] # DataFrame
print(s.sum()) # 190
head, info, dtypes
Vertical checks every time you meet a new table:
df.head()— first rows (default 5).df.head(2)— only two rows on tiny data.df.info()— row count, nulls, dtypes.df.dtypes— types only.df.shape—(rows, columns).
Course: head, info, dtypes.
What you look for
- Wrong types (sales as text).
- Unexpected null counts.
- Surprising column names with spaces.
Columns as Series — quick stats
df["sales"].sum() # 190
df["sales"].mean() # 95.0
df["sales"].max() # 120
Course: Columns as Series — quick stats.
Instagram-like mini example
Suppose engagement:
| post_id | city | likes |
|---|---|---|
| 1 | Mumbai | 80 |
| 2 | Mumbai | 40 |
| 3 | Pune | 70 |
- DataFrame holds all three posts.
df["likes"].sum()→ 190.- Later groupby will split Mumbai 120 vs Pune 70.
Common beginner mistakes
| Mistake | What happens | Fix |
|---|---|---|
Forget import pandas as pd |
NameError | Import first cell |
df.sales with weird column names |
Awkward / fails | Prefer df["sales"] |
| Trust shape without head | Silent wrong file | Always head() |
| Edit a Series and expect magic | Confusion | Know Series vs frame |
Ravindra Bagale's Tip
Before any chart, print head() and one sum you can re-add on paper. If 190 fails, stop — the table is wrong, not your IQ. Samajla ka?
Practice task
In Jupyter:
- Build the two-row shop DataFrame above.
- Print
head(),info(), andsalessum. - Add a third city Nashik with sales 30; new sum should be 220.
- Write one Markdown note: “Series = likes column; DataFrame = full posts table.”
Samajla ka? Series = one column. DataFrame = table. head and info before drama. Keep the 190 check. Aata pudhe jaauya.
Frequently asked questions
What is a Series?
A one-dimensional labelled array — usually one column of a DataFrame.
What is a DataFrame?
A two-dimensional table with labelled columns (and an index for rows).
Why head() before fancy plots?
You confirm columns and sample values before you trust any chart.
What does info() show?
Column names, non-null counts and data types — a fast health check.
Is the index the same as a column?
The index labels rows. You can reset_index later if you need it as a normal column.
Course links?
Chapter 5 Series and DataFrame lessons — linked at the end.