I want to set the column width equal to the max string length in that column, actually I want to adjust the width of the column.
Here is my code:
styler = df.style
for column in df:
column_length = df[column].astype(str).str.len().max()
#styler.set_properties(subset=[column], **{'width': '200px'})
styler.set_properties(subset=[column], **{'width': str(column_length)+'px'})
styler.to_excel('C:/Users/test.xlsx', index=False)
The column width is not set in the exported excel file, what am I doing wrong?