Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading