Reputation: 1323
I am so sorry for asking this, but for some reasons, I have spent some minutes figuring this out but I am not getting it.
I have a dataframe
, something of this nature
df
Output:
TypePro
["JJ", "KK"]
["JK", "RJ"]
["JK"]
["JK"]
I am trying to filter the dataframe
:
df_JJ_KK = df[df.TypePro == ["JJ", "KK"]]
But I get the following error: ValueError: Lengths must match to compare
Please how can I solve this issue?
Upvotes: 1
Views: 473
Reputation: 862481
Use list comprehension for filtering:
df = df[[x == ["JJ", "KK"] for x in df.TypePro]]
print (df)
TypePro
0 [JJ, KK]
Or compare tuple
s:
df = df[df.TypePro.map(tuple) == tuple(["JJ", "KK"])]
Upvotes: 1