python pandas.Series.isin with case insensitive -
i want filter out rows 1 of dataframe's column data in list.
df[df['column'].isin(mylist)] but found it's case sensitive. there method using ".isin()" case insensitive?
one way comparing lower or upper case of series same list
df[df['column'].str.lower().isin([x.lower() x in mylist])] the advantage here not saving changes original df or list making operation more efficient
consider dummy df:
color val 0 green 1 1 green 1 2 red 2 3 red 2 4 blue 3 5 blue 3 for list l:
l = ['green', 'blue'] you can use isin()
df[df['color'].str.lower().isin([x.lower() x in l])] you get
color val 0 green 1 1 green 1 4 blue 3 5 blue 3
Comments
Post a Comment