I am having difficulties in using the str functions when I iterate the df. It gave me "AttributeError: 'str' object has no attribute 'str'" . I checked the datatype and it is a str object.
I want to check it there is substring "fruit" exists in a column. If it does not exist, I would like to append the word "fruit" at the end of the existing value in the row. E.g. "strawberry" ->"strawberry fruit"
code:
for index, row in test_df1.iterrows():
name = row['fruit']
test = row['fruit'].str.extract(r'(\w+)$')
if test != 'fruit':
row['fruit'] = test + " fruit"
I would appreciate some advice. Thank you.