4

I have df:

df = pd.DataFrame({'CaseNo':[1,1,2,2,2,2],
                    'Test1':['180','189','328','328','266','256'],
                    'Test2':['20','21','33','30','28','15'],
                    'Test3':['55','55','58','64','68','58'],
                    'Age':['65','65','45','45','45','45']})

enter image description here

In Python, after pivoting with this code:

df = (pd.pivot_table(s, index=["CaseNo","Age"],
                      aggfunc=["last", list]).reset_index())

I get this:
enter image description here
The columns look weird here. How can I format the cols to look like this:

enter image description here

spidermarn
  • 959
  • 1
  • 10
  • 18

0 Answers0