【问题标题】:Relative path not working in Pandas python in Jupyter notebook相对路径在 Jupyter 笔记本中的 Pandas python 中不起作用
【发布时间】:2018-05-03 21:46:38
【问题描述】:

我的文件夹结构是:

datasets/file.csv
source/code.ipynb

我想从内部访问名为 file.csv 的文件。

import pandas as pd
data = pd.read_csv("../datasets/file.csv")

这给了我错误:ParserError: Error tokenizing data. C error: Expected 1 fields in line 68, saw 2

如何在 pandas python 中使用相对路径访问文件? 我在带有 Jupyter 笔记本的 Windows 8.1 中使用 Python3.6 和 Anaconda。

【问题讨论】:

  • csv 中使用的分隔符(分隔符)是什么?

标签: python-3.x pandas jupyter-notebook


【解决方案1】:

ParseError 表示您的错误在于解析文件,而不是定位和打开它。要验证这一点,请尝试:

test_file = open('../datasets/file.csv')
for line in test_file:
    print(line.strip())

这应该打印出 file.csv 中的行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    相关资源
    最近更新 更多