Let's take this data frame below as an example:
df = pd.DataFrame({
'a':[1,2,3,4],
'b':[2,4,6,8],
'c':[True,True,False,False]
})
>df
a b c
0 1 2 True
1 2 4 True
2 3 6 False
3 4 8 False
I have different ways to select column a where column c equal to True:
First way:
df.loc[df.c == True, 'a']
Second way:
df.loc[df['c'] == True, 'a']
Third way:
df.a[df['c'] == True]
All those get the same result:
0 1
1 2
Name: a, dtype: int64
And there are other operations like df.a[df.c == True]
can did it.
I just wondering is there any difference between indexing operations (.loc) ([ ]) and (.).