Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative path not working in Pandas python in Jupyter notebook

my folder structure is :

datasets/file.csv
source/code.ipynb

from within i want to access the file named 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

How to access file using relative path in pandas python? I am using Python3.6 with Anaconda in Windows 8.1 with Jupyter notebook.

like image 202
TutuGeorge Avatar asked Oct 27 '25 10:10

TutuGeorge


1 Answers

The ParseError indicates that your error is in parsing the file, not locating and opening it. To verify this, try:

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

This should print out the lines in file.csv.

like image 147
Oppy Avatar answered Oct 29 '25 00:10

Oppy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!