pythonpandaslatex

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.


Solution

  • 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]))