I have a pandas dataframe: key val
A 1A 2B 1B 3C 1C 4
I want to get do some dummies like this:
A 1100b 1010c 1001
I have a pandas dataframe: key val
A 1A 2B 1B 3C 1C 4
I want to get do some dummies like this:
A 1100b 1010c 1001
Here is something that I used for my case and tried to apply on yours as far as I could understand the problem
dfkey1 key2
0 A 1
1 A 2
2 B 1
3 B 3
4 C 1
5 C 4pd.get_dummies(df, columns=['key2']).groupby(['key1'], as_index=False).sum()
Output:
key1 key2_1 key2_2 key2_3 key2_4
0 A 1.0 1.0 0.0 0.0
1 B 1.0 0.0 1.0 0.0
2 C 1.0 0.0 0.0 1.0