[英]Pandas Dataframe to_csv format output
I can't find a way to control the output of each column dataframe. 我找不到控制每列数据帧输出的方法。 From the following code:
从以下代码:
df.to_csv('dfnc.txt',
sep=' ',
float_format='%.8f',
cols=['cycle','passs','ip','lon','lat'],
index=False)
I'm getting this: 我明白了:
1.00000000 1.00000000 543.00000000 23.15881870 -64.70485950
1.00000000 1.00000000 544.00000000 23.10356160 -64.64569150
1.00000000 1.00000000 545.00000000 23.04852510 -64.58650550
1.00000000 1.00000000 546.00000000 22.99370760 -64.52730150
1.00000000 1.00000000 547.00000000 22.93910770 -64.46807990
And I want this: 我想要这个:
1 1 543 23.15881870 -64.70485950
1 1 544 23.10356160 -64.64569150
1 1 545 23.04852510 -64.58650550
1 1 546 22.99370760 -64.52730150
1 1 547 22.93910770 -64.46807990
Many thanks for the help. 非常感谢您的帮助。
我想你可以第一次只是转换到第三columns
到int64
写入CSV文件(如果你检查之前.types
,我相信他们都是float64
):
df[['cycle', 'passs', 'ip']]=df[['cycle', 'passs', 'ip']].astype(int64)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.