FileNotFoundError:使用 pandas [英] FileNotFoundError: using Pandas

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

问题描述

我举了一个例子,出现以下错误,不知道为什么.

I ran an example, I get the following errors and don't know why.

# Import pandas as pd
import pandas as pd

# Import the cars.csv data: cars
cars = pd.read_csv('cars.csv')

# Print out cars
print(cars)

当我跑步时,我得到:

Traceback (most recent call last):
  File "C:/Users/gaara_000/PycharmProjects/firstPj/index.py", line 2, in <module>
    cars = pd.read_csv('cars.csv')
  File "C:\Users\gaara_000\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 655, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\gaara_000\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 405, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "C:\Users\gaara_000\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 764, in __init__
    self._make_engine(self.engine)
  File "C:\Users\gaara_000\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 985, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "C:\Users\gaara_000\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 1605, in __init__
    self._reader = parsers.TextReader(src, **kwds)
  File "pandas\_libs\parsers.pyx", line 394, in pandas._libs.parsers.TextReader.__cinit__ (pandas\_libs\parsers.c:4209)
  File "pandas\_libs\parsers.pyx", line 710, in pandas._libs.parsers.TextReader._setup_parser_source (pandas\_libs\parsers.c:8873)
FileNotFoundError: File b'cars.csv' does not exist

我认为这是正确的代码.

I think this is correct code.

我从 https://www.learnpython.org/en/Pandas_Basics 谢谢,我已经解决了

I got this code from https://www.learnpython.org/en/Pandas_Basics Thanks, i fixed that

推荐答案

这是因为您没有cars.csv文件.打开文本编辑器,并在相同目录中创建与.py文件相同的以下文件.

It's because you have no cars.csv file. Open a text editor and create the following file in the same directory as your .py file.

cars.csv:

CarName,Price
Bmw,50000$
Audi,20000$
Ferrari,100000$

现在尝试运行代码.然后您将得到输出,

Now try running the code. And you'll get the output,

   CarName    Price
0      Bmw   50000$
1     Audi   20000$
2  Ferrari  100000$

所以pd.read_csv()所做的是读取一个csv文件(默认的定界符,,您也可以更改它)

So what pd.read_csv() does is reads a csv file (default delimiter is , you can change that too)

这篇关于FileNotFoundError:使用 pandas 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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