I have ten dataframes with same column names 'Name' and 'data' respectively.
Using groupby and aggregation for all the dataset I am able to get the desired output but it is a lot of effort for ten dataset's and the margin of error increases because I need to maintain these dataset's separate. examples and codes provided below.
Df1:
Name data
Foo Product
Foo Misc
Bar Product
Bar Item
Df2:
Name data
Foo Misc
Foo Product
Bar Product
Bar Item
Desired output:
Df1:
Name data
Foo Product,Misc
Bar Product,Item
Df2:
Name data
Foo Misc, Product
Bar Product,Item
Currently I am using the below code to achieve this task
Group1= Df1.groupby('Name')['data'].agg(['data',','.join)]).reset_index()
Group2 = Df2.groupby('Name')['data'].agg(['data',','.join)]).reset_index()
Have tried the below but did not work
Group = [Df1,Df2]
for df in Group:
df.groupby('Name')['data'].agg(['data',','.join)]).reset_index()
Also based on some suggestions tried the below
Group = [Df1,Df2]
for df in Group:
df = df.groupby('Name')['data'].agg(['data',','.join)]).reset_index()
Both did not produce any result no error on code but it's giving me the file without any changes.
for df in Group: df = df.groupby['Name']...?NameCol the same in both DataFrame?