I have long headers for some of my columns in my data frame, and I would like them to wrap text. I know that this functionality is built into pandas, just like me:
pd.DataFrame(np.random.randn(2, 10),
columns=['Very Long Column Title ' + str(i) for i in range(10)])
DataFrame with wrapped column names
But if I have fewer columns, the headers will not wrap:
pd.DataFrame(np.random.randn(10, 2),
columns=['Very Long Column Title ' + str(i) for i in range(2)])
DataFrame does not include column names
I also tried manually inserting a new line:
import pandas as pd
pd.DataFrame(np.random.randn(10, 2),
columns=['Very Long \n Column Title ' + str(i) for i in range(2)])
But this gives the same result as above.
I found similar answers on this topic:
Jupyter, , , pandas.