How to group rows and add new columns.
See the example:
import pandas as pd
df = pd.DataFrame({
'name': ['Andy', 'Bob', 'Chad', 'Andy', 'Chad', 'Bob', 'George', 'Hank'],
'col_1': ['A1', 'A2', 'A3', 'A4', 'B1', 'B2', 'B3', 'B4'],
'col_2': [1, 1, 2, 2, 1, 1, 2, 2]
})
df.groupby(by="name")
df
This generates the following result:
name col_1 col_2
0 Andy A1 1
1 Bob A2 1
2 Chad A3 2
3 Andy A4 2
4 Chad B1 1
5 Bob B2 1
6 George B3 2
7 Hank B4 2
But I need it to look like this:
name col_1 col_2 col_1 col_2
0 Andy A1 1 A4 2
1 Bob A2 1 B2 1
2 Chad A3 2 B1 1
3 George B3 2
4 Hank B4 2
Thanks