简体   繁体   English

Python 根本不会读取 CSV 文件

[英]Python will not read the CSV file at all

I have tried this over and over many times and it still will not work.我已经反复尝试了很多次,但仍然无法正常工作。 All that I need to do is to read a csv file, but my program will not do it.我需要做的就是读取 csv 文件,但我的程序不会这样做。 I have tried the pandas.read_csv() and it just says it does not have that attribute: My error message我已经尝试过pandas.read_csv()它只是说它没有该属性:我的错误消息

I have also tried importing csv and reading it that way but it refuses to admit that there is a file there: My other error message我也尝试过导入 csv 并以这种方式阅读它,但它拒绝承认那里有一个文件:我的其他错误消息

And here is my code for pandas:这是我的 pandas 代码:

pd.read_csv('data.csv')

And my code for the rest:还有我的 rest 代码:

with open('data.csv') as csv_file:
    csv_reader = csv.DictReader(csv_file)

    row = next(csv_reader)
    print(row)

And last but not least, here is the proof that the file exists: Proof最后但并非最不重要的一点是,这是文件存在的证明:证明

Do not create modules using library names.不要使用库名称创建模块。 Rename pandas.py.重命名 pandas.py。 Try again.再试一次。

df= pd.read_csv('data.csv')

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

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