简体   繁体   English

逗号分隔符 CSV 导入为 Pandas 数据框

[英]Comma Delimiter CSV Import as Pandas Data Frame

I have a very simple csv file called detail.csv that contains data like below:我有一个名为 detail.csv 的非常简单的 csv 文件,其中包含如下数据:

Name,Town
John,NY
Charlie,LA

I tried to import it using the usual way as我尝试使用通常的方式导入它

df = pd.read_csv(r'path', sep = ',')

It usually works when the separation is ;它通常在分离时起作用;

What did I do wrong?我做错了什么? I have been browsing this around the internet, but unable to get the answer.我一直在互联网上浏览这个,但无法得到答案。

You are not passing an actual path.您没有通过实际路径。 You're passing in a raw string value called path .您正在传递一个名为path的原始字符串值。 You should remove the quotes:您应该删除引号:

df = pd.read_csv(path, sep = ',')

Also, you can try to use delimiter , instead of sep此外,您可以尝试使用delimiter ,而不是sep

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

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