Home > Mobile >  Python pandas lower data AttributeError: 'Series' object has no attribute 'lower'
Python pandas lower data AttributeError: 'Series' object has no attribute 'lower'

Time:02-02

I want to lower data taken from pandas sheet and trim all spaces then to look for an equality.

df['ColumnA'].loc[lambda x: x.lower().replace(" ", "") == var_name]

Code is above. It says pandas series has no lower method. But I need to search for data inside column A via pandas framework while lowering all letters to small and whitespace trimmering. Any other idea, how can I achieve in pandas?

CodePudding user response:

In your lambda function, x is a Series not a string so you have to use str accessor:

df['ColumnA'].loc[lambda x: x.str.lower().replace(" ", "") == var_name]

Another way:

df.loc[df['ColumnA'].str.lower().str.replace(' ', '') == var_name, 'ColumnA']
  • Related