I would like to wrap the column names of a data frame to some specific width. For instance, transform
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
0 -1.526078 0.258110
1 0.263490 -0.268635
2 -1.264121 -1.257454
to something like
aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa
aaaaaaaaaaaaa aaaaaaaaaaaaa
0 -1.526078 0.258110
1 0.263490 -0.268635
2 -1.264121 -1.257454
There is a solution to this problem in this stackoverflow post, but it only works in jupyter notebooks, not in regular python.
Code to reproduce the dataframe:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(3, 2), columns=['a' * 30] * 2)
print(df)