Skip to content Skip to sidebar Skip to footer

Pandas Set Cell Format In Excel Writer

I am using pandas to read and write excel files with python (xlsx files, using openpyxl). Part of my data is text that looks like numbers. For instance, in the original excel file,

Solution 1:

I think in the worst case you can manipulate cells directly. I don't have Excel installed but maybe you can check if this works.

In [67]: df=pd.DataFrame ([123456789012345])

In [68]: writer = pd.ExcelWriter ('e.xlsx', engine='openpyxl')

In [69]: df.to_excel (writer, 'sheet1')

In [70]: ws = writer.sheets['sheet1']

In [71]: ws['A1'].style.number_format.format_code='@'

In [72]: writer.save ()

In [73]: pd.read_excel ('e.xlsx')
Out[73]: 
                 0
0  123456789012345

Post a Comment for "Pandas Set Cell Format In Excel Writer"