I have the following dfs
a = {"A":[123],"B":[19],"C":[18],"J":[220],'name':['group_1']}
b = {"A":[123],"B":[80],"C":[10],"D":[3],'name':['group_2']}
df1 = pd.DataFrame(a)
df2 = pd.DataFrame(b)
when appending them I get:
df = df1.append(df2).fillna(0).reset_index(drop=True)
A B C D J name
0 123 19 18 0.00 220.00 group_1
1 123 80 10 3.00 0.00 group_2
I wish to have this:
group_1 group_2
A 123 123
B 19 80
C 18 10
D 0 3
J 220 0
I was hoping either melt or pivot_table will do the trick but the results are not as expected. Exmaple: df.pivot_table(index=['A','B','C','D','J'], columns=['name'], aggfunc='count') will not show the 'name' (group_1/2) as columns.