Home > database >  Title to be displayed below the headers
Title to be displayed below the headers

Time:08-31

How can I display Colors title below the headers in a table? Currently, I have Colors title on top of the headers but I need Colors title below the headers as a final output. How can I achieve this?

enter image description here

CodePudding user response:

In Pandas dataframe, if you want to show the name Colors below the header, you can rename your Column 1 as Colors and then set it as index.

data = {'Colors':['White','Black','Orange','Blue'],'Col2':[15,14,28,3],'Col3':[5,6,0,5]}

df = pd.DataFrame(data)

df

   Colors  Col2  Col3
0   White    15     5
1   Black    14     6
2  Orange    28     0
3    Blue     3     5

df.set_index('Colors', inplace=True)

        Col2  Col3
Colors            
White     15     5
Black     14     6
Orange    28     0
Blue       3     5

As you can see, the column Colors became index and your dataframe is left with two columns: Col2 and Col3.

  • Related