0

This is how my data set looks like.

df1 
        A   B   C   D
0       41  John  2022-11-20  32
1       54  John  2022-11-19  65
2       15  John  2022-11-18   9
3       39  John  2022-11-17  97
4        4  John  2022-11-16  54
...     ..  ..  ..  ..
999995  48  John  2019-11-20  25
999996  16  John  2019-11-19  28
999997   1  John  2019-11-18  14
999998  66  John  2019-11-17  70
999999  51  John  2019-11-16  99

df2 

        A   B   C   D
0       41  Adam  2022-11-20  32
1       54  Adam  2022-11-19  65
2       15  Adam  2022-11-18   9
3       39  Adam  2022-11-17  97
4        4  Adam  2022-11-16  54
...     ..  ..  ..  ..
999995  48  Adam  2019-11-20  25
999996  16  Adam  2019-11-19  28
999997   1  Adam  2019-11-18  14
999998  66  Adam  2019-11-17  70
999999  51  Adam  2019-11-16  99

This is the result of the data set I am looking for.

           2022-11-20   2022-11-19   2022-11-18   2022-11-17
John    a       41        54            15           39
        d       32        65            9           97
Adam    a       41        54            15           39
        d       32        65            9           97



Please help thank you trying to look to make the data set clean. I tried concat(dfs, axis=1) but the result isn't that clean.

johnsi
  • 1
  • 1
  • Use `pd.concat([df1, df2]).pivot('B','C','A')` – jezrael Nov 03 '22 at 09:03
  • Thank you its working amazing, however with only one value data. Is it possible to add in column D as well? I tried d.concat([df1, df2]).pivot('B','C',values=['A','D']) but that basically append after data 'A'. – johnsi Nov 03 '22 at 09:40
  • Use `pd.concat([df1, df2]).pivot(index=['B','D'],columns='C',values='A')` – jezrael Nov 03 '22 at 09:49
  • 1
    Amazing. I ran again with pd.concat and combined A and D column. Not sure if its the best practice but looks okay. Thank you @jezrael – johnsi Nov 03 '22 at 10:02

0 Answers0