[英]Cannot import local file with pd.read_csv on Mac
I have a download.csv file stored in a folder "Python" on my local Desktop.我在本地桌面上的“Python”文件夹中存储了一个 download.csv 文件。 Now, I open my Jupyter Notebook locally and want to read this file.
现在,我在本地打开我的 Jupyter Notebook 并想阅读这个文件。 I use:
我用:
import pandas as pd
df = pd.read_csv('Desktop/Python/download.csv')
df.head()
However, it gives me an error:但是,它给了我一个错误:
FileNotFoundError: [Errno 2] File b'Desktop/Python/download.csv' does not exist: b'Desktop/Python/download.csv'
FileNotFoundError: [Errno 2] 文件 b'Desktop/Python/download.csv' 不存在:b'Desktop/Python/download.csv'
What needs to change here?这里需要改变什么?
我想通了: df = pd.read_csv('~/Desktop/Python/download.csv',error_bad_lines=False)
Your Desktop
is actually located in your user space (your home folder, abbreviated with ~
, which expands to /Users/<username>
).您的
Desktop
实际上位于您的用户空间(您的主文件夹,缩写为~
,扩展为/Users/<username>
)。 Replace your path with:将您的路径替换为:
~/Desktop/Python/download.csv
Like so:像这样:
df = pd.read_csv('~/Desktop/Python/download.csv')
I agree with @wcarhart.我同意@wcarhart。 I setup a csv file just like you have @coco84hh but without the error_bad_lines=False).
我设置了一个 csv 文件,就像你有@coco84hh 一样,但没有 error_bad_lines=False)。 I have df = pd.read_csv('~/Desktop/Python/download.csv') print(df)
我有 df = pd.read_csv('~/Desktop/Python/download.csv') print(df)
It works.有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.