.isin() returning a blank dataframe

Question:

My DataFrame:

My Dataframe

Trying…

Does not work

Nope…

Does not work

Still nope…

AND YET…

Huh?

Any idea why I can’t filter this dataframe by a list using isin?

I’m expecting it to return one or more rows where the Chord Notes column equals the list [‘C’,’E’,’G’]

Answers:

you can still use isin() but since the values under ‘Chord Notes’ are actual list object so you have to pass that list object i.e ['C','E','G'] in isin() method

output = full_chords[full_chords['Chord Notes'].isin([['C','E','G']])]

Or with map() (kind of loop under the hood):

output = full_chords[full_chords['Chord Notes'].map(lambda x_x==['C','E','G'])]

Or

Other way around is to typecast that column to string(not recommended but still an option tho):

output = full_chords[full_chords['Chord Notes'].astype(str).eq("['C','E','G']")]
Answered By: Anurag Dabas
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.