I have the following table:
| Name | Age | Data_1 | Data_2 |
|---|---|---|---|
| Tom | 10 | Test | |
| Tom | 10 | Foo | |
| Anne | 20 | Bar |
How I can merge this rows to get this output:
| Name | Age | Data_1 | Data_2 |
|---|---|---|---|
| Tom | 10 | Test | Foo |
| Anne | 20 | Bar |
I tried this code (and some other related (agg, groupby other fields, et cetera)):
import pandas as pd
data = [['tom', 10, 'Test', ''], ['tom', 10, 1, 'Foo'], ['Anne', 20, '', 'Bar']]
df = pd.DataFrame(data, columns=['Name', 'Age', 'Data_1', 'Data_2'])
df = df.groupby("Name").sum()
print(df)
But I only get something like this:
| c2 | |
|---|---|
| Name | |
| -------- | -------------- |
| Anne | Foo |
| Tom | Bar |