› Forums › Python › Pandas (Python library) › Why Does Pandas Use Double Brackets: `df[[“area_m2”, “price_usd”]]`?
- This topic is empty.
-
AuthorPosts
-
February 22, 2026 at 7:29 am #6130
If you are learning Python Pandas for data analysis, you may have noticed something confusing:
Why do we sometimes write:
df[["area_m2", "price_usd"]]instead of just:
df["area_m2", "price_usd"]Why are there two sets of brackets?
In this post, we’ll explain this in a simple, beginner-friendly way.
✅ Understanding
df[...]in PandasIn Pandas, square brackets
[]are used to select data from a DataFrame.Think of it like this:
df[ ... ]means:
“Get something from this DataFrame.”
It works like a dictionary:
my_dict["name"]
✅ Selecting a Single Column
When you want one column, you pass a string:
df["area_m2"]What happens here?
"area_m2"is a column name- Pandas returns a Series (one column only)
Example:
type(df["area_m2"]) # pandas.core.series.Series
✅ Selecting Multiple Columns
When you want more than one column, you must use a list.
In Python, a list looks like this:
["area_m2", "price_usd"]So in Pandas, you write:
df[["area_m2", "price_usd"]]What does this mean?
- Inner
[]→ Python list of column names - Outer
[]→ DataFrame selection
So it means:
“From df, select these columns.”
✅ Why Two Brackets Are Needed
Each bracket has a different role:
🔹 Outer Brackets → DataFrame Indexing
df[ ... ]This tells Pandas:
“I want to access something from df.”
🔹 Inner Brackets → List of Columns
["area_m2", "price_usd"]This tells Pandas:
“These are the columns I want.”
✅ Together:
df[["area_m2", "price_usd"]]Means:
Select these columns from df.
✅ Equivalent Way (Easier to See)
You can also write:
columns = ["area_m2", "price_usd"] df[columns]This works the same way.
The double brackets are just a shortcut.
❌ Common Mistakes Beginners Make
❌ Mistake 1: Using Commas Without a List
df["area_m2", "price_usd"] # ❌ WrongWhy?
Python treats this as a tuple, not a list.
Pandas doesn’t accept this here.
❌ Mistake 2: Chaining Brackets
df["area_m2"]["price_usd"] # ❌ WrongWhy?
- First selects
"area_m2" - Then tries to find
"price_usd"inside it - It doesn’t exist
So it fails.
✅ Difference in Output: Series vs DataFrame
This is very important.
One Column → Series
df["area_m2"]Returns:
pandas.Series
Multiple Columns → DataFrame
df[["area_m2", "price_usd"]]Returns:
pandas.DataFrameThis matters because some methods work differently on Series and DataFrames.
✅ Practical Example
import pandas as pd data = { "area_m2": [50, 70, 90], "price_usd": [100000, 150000, 200000], "city": ["Delhi", "Mumbai", "Pune"] } df = pd.DataFrame(data)Select One Column
df["area_m2"]Select Multiple Columns
df[["area_m2", "price_usd"]]Get Summary Statistics
df[["area_m2", "price_usd"]].describe()
✅ Quick Rule to Remember
Task Syntax One column df["col"]Many columns df[["col1", "col2"]]👉 Rule:
Multiple columns = list = extra brackets
🧠 Why Pandas Uses This Design
Pandas follows standard Python logic:
- One item → string
- Many items → list
Instead of inventing new syntax, it uses normal Python data types.
This makes Pandas consistent and flexible.
🎯 Final Thoughts
The “double brackets” in Pandas are not special symbols.
They simply mean:
- Outer
[]→ Access DataFrame - Inner
[]→ List of columns
Once you understand this, Pandas indexing becomes much easier.
-
AuthorPosts
- You must be logged in to reply to this topic.

