nz_21
nz_21

Reputation: 7343

Pandas: for loop weirdness

I'm completely baffled by the below snippets. I expected both to give me the same output, but that doesn't seem to be the case.

enter image description here

Upvotes: 0

Views: 42

Answers (1)

charles
charles

Reputation: 1055

I think the top snippet is returning the length of the entire dataframe.

Consider :

import pandas as pd
df = pd.DataFrame.from_dict({"A":[1, 1, 0, 0, 1]})
print(len(df["A"]==1))

Output : 5

Upvotes: 1

Related Questions