0

I was trying to run but I keep getting file not found for my csv file however the file is there. This could be an issue with the path separator. How do I fix it? Can I add the file path to the code or no?

path = 'D:/ecg/ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.1'
sampling_rate=100


Y = pd.read_csv(path+'ptbxl_database.csv', index_col='ecg_id')
Y.scp_codes = Y.scp_codes.apply(lambda x: ast.literal_eval(x))

enter image description here

Colim
  • 1,283
  • 3
  • 11
matt hamde
  • 11
  • 2
  • You are missing a `/` at the end of `path`... Also see [Windows path in Python](https://stackoverflow.com/q/2953834/6045800) – Tomerikoo Jun 29 '22 at 08:10
  • This is why it's better to use `os.path` or `pathlib` to do path-related operations - they take care of these things for you. See also [Platform independent path concatenation using "/" , "\"?](https://stackoverflow.com/q/10918682/6045800) – Tomerikoo Jun 29 '22 at 08:11

3 Answers3

1

You need a / at the end of path.

It should be path = 'D:/ecg/ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.1/

If the error persists, try using \\instead of /

Abdeslem SMAHI
  • 453
  • 2
  • 12
1

Based on screenshot, it looks like you have appended workspace path to your file path.

You need to use path separator(/) before your file name .

Ashish Patil
  • 4,428
  • 1
  • 15
  • 36
1

To avoid this kind of error, use "os" library to compose the paths

path = 'D:/ecg/ptb-xl-a-large-publicly-available-electrocardiography-dataset-1.0.1'
sampling_rate=100

#This path is independent of the OS
#So it will run on Linux or Windows, or any other OS
import os.path
fullFilePath = os.path.join(path, 'ptbxl_database.csv')


Y = pd.read_csv(fullFilePath, index_col='ecg_id')
Y.scp_codes = Y.scp_codes.apply(lambda x: ast.literal_eval(x))
Colim
  • 1,283
  • 3
  • 11