can you help me with the column autowidth in excel. I have a data frame named "fp" and when i export it in excel, i have the following output Output1. i would like to adjust automatically the width of column so that it will look like this: Desired output.
the initial code is
filename = filedialog.askopenfilename(initialdir="/", title="Select file to convert")
fichierp = pd.read_excel(r'%s' % filename, index_col=1)
fp = fichierp.iloc[:, [0, 1, 2, 5, 8, 10,13]]
what i have tried is:
for column in fp:
column_width = max(fp[column].astype(str).map(len).max(), len(column))
col_idx = fp.columns.get_loc(column)
fp.set_column(col_idx, col_idx, column_width)`