I have one column in the DataFrame that is a name. Inside this name there are patterns that I want to locate, and create a category in other column of same DataFrame. For example :
Name
name first RB LA a
name LB second
RB name third
name LB fourth
I want the name with the same pattern to be in the same category, displayed in the other column
What I want :
Name Example
name first RB LA a Round Blade category
name LB second Long Biased category
RB name third Round Blade category
name LB fourth Long Biased category
I have a DataFrame, not a list, there are several other columns in it. And there are not only two categories, but several ones.
What I have Tried :
df.loc[df['Name']=="RB", 'Example'] = "RB category"
But it does not work since it must be an exact match
Another attempt :
if df[['Name'].str.contains("RB")] :
(...)
But it gives me error :
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I tried to add to .bool() or .any(), but or the error persist or nothing happens when I run the line.
Thank you.
.str.contains(), then?.loc[], like you did in the first snippet.