I want to extract text from a column in my df where the df has column text like:
df:
text
@bobby
@mike
why @mike
huh, @brad
@brad
cmon @Sunny_Bat
@Sunny_Bat
@But_ten
@g2
@Mikey/fj
@4242343
I have code that gives me the extracted text or word after @ like below:
df['text'].str.extract(r"@([A-Za-z_]+([0-9]+)*)")[0]
This gives me the output I want by extracting the word if it exists but is not a number as the expected output below:
Desired Output:
text | new column
@bobby bobby
@mike mike
why @mike mike
huh, @brad brad
@brad brad
cmon @Sunny_bat Sunny_bat
@Sunny_Bat Sunny_bat
@But_ten But_ten
@g2 g2
@Mikey/fj Mikey
@4242343 NaN
But what I am missing is I want my new column to have values that exist in another column in the same df or an array of unique values of that column called unique_values like below:
isin(unique_values))
I am trying to add via something like:
where(lambda x: x[0].isin(name_list))
but not sure how to add to my above code
Also,
Where I can add the isin to the end of the code above to output only values or words that exist in this array, also I want the outputted words to all be lowercase only since the words in unique values are lowercase but in the text column that is being extracted are not lower case.
Thanks!