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

AttributeError: 'str' object has no attribute 'str' how to solve this

When I apply f"" string on my text data it procduces the following error. AttributeError: 'str' object has no attribute 'str'.

The simple code is below, I am providing just one line so that it will save your time. I just want to apply f"" in this way. I know the problem but don’t know how to figure it. Thanks

caption = f"{caption.str.lower().str.rstrip('.')}"

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 :

You may be familiar with the pandas library’s .str accessor which make pandas ports of python string methods available to a Series. But if you’re working with python builtin str types, you don’t need the .str accessor. Simply call:

caption = f"{caption.lower().rstrip('.')}"

See the python builtin types docs on string methods for more info.

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