Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14360

FileNotFoundError when I call a file with read_csv from an other directory [duplicate]

$
0
0

In my code I have a file called location.py where I read a file that I use for a function assign:

import pandas as pdfilename = '../../Dataset/Import.csv'df = pd.read_csv(filename, sep='\t', encoding='utf-16')def assign(df = df):

Now, I would like to use the function assign in another file, that is in an other directory, but I meet the error:

FileNotFoundError: [Errno 2] No such file or directory:

If I go back in location.py and I change the relative path of the filename, everything works. But I was expecting python to read the relative path of the folder where it is written, not from where I call the function.This is the directory structure

  • Directory a-- location.py
  • Dataset-- Import
  • Directory b-- another directory-- file_from_where_I_call_location.py

I still would like to use a relative path, but how can I solve this issue? I can't keep changing the file path hard coded every time I need it


Viewing all articles
Browse latest Browse all 14360

Trending Articles