Karthi Chowdary Movva
Karthi Chowdary Movva

Reputation: 40

Python pandas dataframe why using double squared brackets

Why does

print(data["column"].shape)

print (1819,) whereas

print(data[["column"]].shape)

prints (1819,1)

Upvotes: 1

Views: 1823

Answers (1)

sarthak
sarthak

Reputation: 508

data["column"] returns a Pandas Series which is always always as shape (n,) i.e. it does not have columns just a single row always.

data[["column"]] returns a Pandas DataFrame which has shape (m, n)

If you want multiple columns in a dataframe you can use the double brackets as follows.

data[["col1", "col2"]]

Upvotes: 4

Related Questions