df.to_csv('dfnc.txt',
sep=' ',
float_format='%.8f',
cols=['cycle','passs','ip','lon','lat'],
index=False)
我明白了:
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
我想要这个:
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
非常感谢您的帮助.
解决方法:
我想你可以在写入CSV文件之前将第1列转换为第3列(如果检查.types,我确定它们都是float64):
df[['cycle', 'passs', 'ip']]=df[['cycle', 'passs', 'ip']].astype(int64)