Diego Palacios
Diego Palacios

Reputation: 1144

How to rotate column names in pandas table to latex method?

I want to create a latex table from a pandas DataFrame, but column names are long, and I want to put them vertically, like this:

table

Currently I am using the to_latex method, but I do not how to rotate the labels.

Upvotes: 5

Views: 1678

Answers (1)

Bastian
Bastian

Reputation: 518

This should work by creating a new list based on the column names with the latex command to rotate by 90° and give this list as parameter for the headers:

df.to_latex(escape=False,header=['\\rotatebox{90}{' + c + '}' for c in df.columns]))  

Upvotes: 7

Related Questions