2024-09-28 22:21:14 发布
网友
我如何防止Python自动将对象写入csv,而不是以原来的格式?例如,我有如下列表对象:
row = ['APR16', '100.00000']
我想按原样写这一行,但是当我使用csv writer的writerow函数时,它写入到csv文件中的值是Apr 16,而只有10。我想保留原来的格式。在
编辑:
代码如下:
结果:
{1美元^
使用pandas:
pandas
import pandas as pd dates = ['APR16', 'MAY16', 'JUN16'] numbers = [100.00000, 200.00000, 300.00000] data = zip(dates,numbers) fd = pd.DataFrame(data) fd.to_csv('test.csv', index=False, header=False) # csv-file fd.to_excel("test.xls", header=False,index=False) # or xls-file
我的终端结果:
产生LibreOffice:
使用
pandas
:我的终端结果:
^{pr2}$产生LibreOffice:
相关问题 更多 >
编程相关推荐