无法使用pandas在python3中加载csv文件 [英] can't load csv file in python3 with pandas

查看:350
本文介绍了无法使用pandas在python3中加载csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我不知道为什么,但是熊猫真的无法在我的python代码中加载我的csv文件.该文件位于我的python项目的同一文件夹中,我正在使用tensorflow,theano,pandas,numpy和matplotlib库. 已经2个小时了,我尝试卸载所有内容,然后再次使用pip3命令重新安装.我卸载了tensorflow,pandas,theano,numpy甚至python2和python3.没有.我还更新和升级了我的Linux发行版.无用.

Hi guys I don't know why but pandas really can't manage to load my csv file in my python code. The file is in the same folder of my python project, I'm working with tensorflow, theano, pandas, numpy and matplotlib libraries. It's been 2 hrs and I tried uninstalling everything and reinstalling once again using the pip3 commands. I uninstalled tensorflow, pandas, theano, numpy, and even python2 and python3. Nothing. I also updated and upgraded my linux distro. useless.

这是我在Spyder3内部终端中执行部分代码时不断遇到的错误:

this is the error I keep getting when I execute the part of my code in the Spyder3 internal terminal:

    dataset = pd.read_csv('Churn_Modelling.csv')
Traceback (most recent call last):

  File "<ipython-input-4-610b2f33ea04>", line 1, in <module>
    dataset = pd.read_csv('Churn_Modelling.csv')

  File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 709, in parser_f
    return _read(filepath_or_buffer, kwds)

  File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 449, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)

  File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 818, in __init__
    self._make_engine(self.engine)

  File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 1049, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)

  File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 1695, in __init__
    self._reader = parsers.TextReader(src, **kwds)

  File "pandas/_libs/parsers.pyx", line 402, in pandas._libs.parsers.TextReader.__cinit__

  File "pandas/_libs/parsers.pyx", line 718, in pandas._libs.parsers.TextReader._setup_parser_source

FileNotFoundError: File b'Churn_Modelling.csv' does not exist

这是奇怪的代码行:

dataset = pd.read_csv('Churn_Modelling.csv')

伙计们怎么了?我也尝试过重命名.

What is wrong with it guys?? I also tried to rename it.

推荐答案

错误消息是FileNotFoundError: File b'Churn_Modelling.csv' does not exist.如果该文件存在,则它不在python脚本的同一工作目录中.

The error message is what it is FileNotFoundError: File b'Churn_Modelling.csv' does not exist. If the file exists, then it is not in the same working directory of your python script.

我会尝试打印当前的工作目录,以检查python是否在正确的目录中查找文件.

I would try printing the current working directory to check whether python is looking for the file in the correct directory.

import os
print(os.getcwd())

或者,您可以使用绝对路径,而不是使用相对路径(例如,Churn_Modelling.csv)导入文件

Alternatively, instead of importing the file using a relative path (e.g., Churn_Modelling.csv), you could use an absolute path

dataset = pd.read_csv('/path/to/file/Churn_Modelling.csv')

另外请注意,在POSIX系统(例如Linux/Mac)中,文件名区分大小写(即Churn_Modellingchurn_modelling不同).

Also, be mindful that in POSIX systems (e.g., Linux / Mac), the file name is case sensitive (i.e., Churn_Modelling is not the same as churn_modelling).

这篇关于无法使用pandas在python3中加载csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆