简体   繁体   English

读取 csv 将 \t 添加到每一列和值

[英]Read csv adds \t to each column and value

When i read my csv当我读到我的 csv

 cs = pd.read_csv(r'file.csv',encoding='utf-8')

it adds a \t to each column and value except of numbers (so to all strings) I downloaded the file from the same source where i have downloaded previous files and there it didn't add it.它为除数字之外的每一列和值添加了一个 \t (所以对所有字符串) I have the same reading command as always我有和往常一样的阅读命令

 \tamplitude_id \tuser_id \tcity \tcountry... \tgp:utm_content \tgp:utm_medium \tgp:utm_source \tgp:utm_term 0 123456789 123456789 \t \t... \t \t \t \t 1 123456789 123456789 \t \t... \t \tpaid \t \t

how can I read it without the \t没有 \t 怎么读

When you see "\t" after reading a file it represents tab and in CSV it usually represents a different column in the same row当您在读取文件后看到"\t"时,它代表tab ,在 CSV 中,它通常代表同一行中的不同列

so adding sep = '\t' to your original command should do the trick:因此将sep = '\t'添加到您的原始命令应该可以解决问题:

cs = pd.read_csv(r'file.csv',sep = '\t' ,encoding='utf-8')

If you have any questions feel free to ask me in the comments.如果您有任何问题,请随时在评论中问我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM