Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- df = pd.DataFrame({'A': ['drama|Action', 'Drama', 'Action'], 'A_split1': ['Drama', 'Drama', 'Action'],'A_split2': ['Action', 'None', 'None'],'Drama': [0, 0, 0], 'Action': [0, 0, 0], 'Western': [0, 0, 0]},
- index = ['a1', 'a2', 'a3'])
- df
- df = pd.DataFrame({'A': ['Drama|Action', 'Drama', 'Action'], 'B':range(3)},
- index = ['a1', 'a2', 'a3'])
- print (df)
- A B
- a1 Drama|Action 0
- a2 Drama 1
- a3 Action 2
- df = df.join(df.pop('A').str.get_dummies())
- print (df)
- B Action Drama
- a1 0 1 1
- a2 1 0 1
- a3 2 1 0
- df = df.join(df['A'].str.get_dummies())
- print (df)
- A B Action Drama
- a1 Drama|Action 0 1 1
- a2 Drama 1 0 1
- a3 Action 2 1 0
Add Comment
Please, Sign In to add comment