相对路径在 Jupyter 笔记本中的 Pandas python 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47395998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Relative path not working in Pandas python in Jupyter notebook
提问by TutuGeorge
my folder structure is :
我的文件夹结构是:
datasets/file.csv
source/code.ipynb
from within i want to access the file named file.csv.
我想从内部访问名为 file.csv 的文件。
import pandas as pd
data = pd.read_csv("../datasets/file.csv")
This is giving me the error : ParserError: Error tokenizing data. C error: Expected 1 fields in line 68, saw 2
这给了我错误: ParserError: Error tokenizing data. C error: Expected 1 fields in line 68, saw 2
How to access file using relative path in pandas python? I am using Python3.6 with Anaconda in Windows 8.1 with Jupyter notebook.
如何在pandas python中使用相对路径访问文件?我在带有 Jupyter 笔记本的 Windows 8.1 中使用 Python3.6 和 Anaconda。
回答by Oppy
The ParseError indicates that your error is in parsing the file, not locating and opening it. To verify this, try:
ParseError 表示您的错误在于解析文件,而不是定位和打开它。要验证这一点,请尝试:
test_file = open('../datasets/file.csv')
for line in test_file:
print(line.strip())
This should print out the lines in file.csv.
这应该打印出 file.csv 中的行。