.isin() returning a blank dataframe
Question:
My DataFrame:
Trying…
Nope…
Still nope…
AND YET…
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']")]
My DataFrame:
Trying…
Nope…
Still nope…
AND YET…
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’]
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']")]