I have a pandas dataframe with a column named “Notes”. It has entries like the example below. I would like to create dummy variable columns based on a list:
Lst=[‘loan’,’Borrower’,’debts’]
That is I’d like to create a binary flag for each entry in the list if the string in the “Notes” column contains it. Can anyone suggest how to do this?
data:
print(data_df[['Id','Notes']][:10])
Id Notes
59 60 568549 added on 11/04/09 > I use my current l...
76 77 I would like to use this loan to consolidate c...
88 89 Borrower added on 06/28/10 > I would really ...
229 230 I just got married and ran up some debt during...
output:
Id Notes loan Borrower debts
59 60 568549 added on 11/04/09 > I use my current l... 0 0 0
76 77 I would like to use this loan to consolidate c... 1 0 0
88 89 Borrower added on 06/28/10 > I would really ... 0 1 0
229 230 I just got married and ran up some debt during... 0 0 1