I have a dataframe in which one column has text information.
print(df):
... | ... | Text |
... | ... | StringA. StringB. StringC |
... | ... | StringZ. StringY. StringX |
... | ... | StringL. StringK. StringJ |
... | ... | StringA. StringZ. StringJ |
I also have a dictionary that has the following:
dict = {'Dogs': ['StringA', 'StringL'],'Cats': ['StringB', 'StringZ', 'StringJ'],'Birds': ['StringK', 'StringY']}
EDIT: i have about 100 dictionary Keys which each have 4+ Values.
What I am hoping to do is create extra columns in the dataframe for each Key in the dictionary and then place a "1" in the column when any of the Values from the dictionary appear.
Therefore the output i am trying to get is:
print(df):
... | ... | Text | Dogs | Cats | Birds
... | ... | StringA. StringB. StringC | 1 | 1 | 0
... | ... | StringZ. StringY. StringX | 0 | 1 | 1
... | ... | StringL. StringK. StringJ | 1 | 1 | 1
... | ... | StringA. StringZ. StringJ | 1 | 1 | 0
EDIT: The issue is I'm not sure how to search for the values within the text column and then return a 1 if found to the Key column. Any help would be much appreciated! Thanks!