奇葩问题pandas

首先,CSV文件:

txt,type
"MOGG
 fgbf 假数据-文本--17",菜
"MOCK #GG
 fgbf 假数据-文本--18",谱
"#美块
",菜

其次,代码

import pandas as pd
df=pd.read_csv('tt.csv')
for i in range(7):
    print(df)
    df.to_csv('tt2.csv',index=False)
    df=pd.read_csv('tt2.csv')

然后,在win系统行为:

 在linux行为:

mac系统如下:

 

有奖竞答:

1.为啥\R\N行为不一样,以及mac下是啥特点(上面有图)

2.win下甚至多系统下,怎么做到兼容(读出和写入行为一样)

答:BUG:DataFrame.to_csv not using correct line terminator on Windows within open block · Issue #38551 · pandas-dev/pandas · GitHub

with open('file1.csv',mode='w',newline='') as f:
    df.to_csv(path_or_buf=f)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值