pythonpandaspandas-locisin

.isin() returning a blank dataframe


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']


Solution

  • 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']")]