I have the following dataframe df (just a sample with 6 rows):
df = pd.DataFrame({'#': [1, 1, 2, 3, 3, 3],
'Name': ['john', 'john', 'max', 'tim', 'tim', 'tim'],
'Phone': ['01234', '98765', '', '', '33445566', ''],
'ID': ['', '', '11111', '2222222', '', ''],
'User': ['', '', '', '', '', 'tim123']})
print(df)
# Name Phone ID User
0 1 john 01234
1 1 john 98765
2 2 max 11111
3 3 tim 2222222
4 3 tim 33445566
5 3 tim tim123
Now I want to merge all entries like # 3 (tim). My desired dataframe should look like this:
# Name Phone ID User
0 1 john 01234
1 1 john 98765
2 2 max 11111
3 3 tim 33445566 2222222 tim123
So I want to combine the columns 'Phone', 'ID' and 'User' for the rows with the same #- and name-column in a dataframe. Do you have any useful suggestions, how I could do this?
Thanks a lot in advance!