python - Why is the result of string.format() a string, even for numbers? -
the following evaluates true:
'{:.2f}'.format(2.0) > '{:.2f}'.format(10.0)
i want write number excel 2 decimals (2 2.00) using dataframe.to_excel
, gets displayed text instead of number in cell.
update:
import pandas pd data_table = [[1.0,2.0,3.0],[4.0,5.0,6.0]] dataframe = pd.dataframe(data_table) writer = pd.excelwriter(filename, engine='xlsxwriter') dataframe.to_excel(writer,float_format='%11.2f', index=false) writer.save()
it still shows 6 instead of 6.00. maybe excel strips 0 when open it
1 2 3 4 5 6
to_excel has float_format option.
Comments
Post a Comment