“CSV 文件不存在"对于带有嵌入引号的文件名 [英] "CSV file does not exist" for a filename with embedded quotes
问题描述
我目前正在学习 Pandas 进行数据分析,但在 Atom 编辑器中读取 csv 文件时遇到了一些问题.
I am currently learning Pandas for data analysis and having some issues reading a csv file in Atom editor.
当我运行以下代码时:
import pandas as pd
df = pd.read_csv("FBI-CRIME11.csv")
print(df.head())
我收到一条错误消息,以
I get an error message, which ends with
OSError:文件 b'FBI-CRIME11.csv' 不存在
OSError: File b'FBI-CRIME11.csv' does not exist
这是文件的目录:/Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv".
Here is the directory to the file: /Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv".
当我尝试以这种方式运行时:
When i try to run it this way:
df = pd.read_csv(Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv")
我收到另一个错误:
NameError: name 'Users' 未定义
NameError: name 'Users' is not defined
我也将此目录放入编辑器设置中的项目主页"字段中,但我不太确定它是否有任何区别.
I have also put this directory into the "Project Home" field in the editor settings, though I am not quite sure if it makes any difference.
我敢打赌有一种简单的方法可以让它发挥作用.我将衷心感谢您的帮助!
I bet there is an easy way to get it to work. I would really appreciate your help!
推荐答案
你试过了吗?
df = pd.read_csv("Users/alekseinabatov/Documents/Python/FBI-CRIME11.csv")
也许
df = pd.read_csv('Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv"')
(如果文件名有引号)
这篇关于“CSV 文件不存在"对于带有嵌入引号的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!