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('.')}"


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.

Answered By – Michael Delgado

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published