0

i am trying to load .dat file to csv file but i am getting multiple errors. i am trying to write this below code import pickle as cPickle x = cPickle.load(open('s01.dat', 'rb'))

but my error is "no such file or directory: 's01.dat' kindly help me. if you say i can share s01.dat file as well.

  • 1
    I think the file is in a different directory as the directory where you run the program. Use full path, or move the data file together where you execute the script (or execute the script where you have the .dat file). You have many options, you should just check what it is more convenient for the thing you are doing – Giacomo Catenazzi Dec 06 '21 at 11:02
  • path is correct and i also have tried by putting both files in same folder. i dont know whats the issue. i am trying with numpy and pandas asell but still getting same directory error. – Sidra Rafique Dec 06 '21 at 11:32
  • The problem it is that the file is not in the directory you are expecting. Numpy, pandas, etc. will not solve it (they are based on basic Python). So check further. What do you use to execute python? Which command? If it is an IDE, check the setting "working directory". If you use a script, check if you change directory. Or also in code, maybe you are changing the working directory. The problem is that (for sure), but we have not much information on your code, and how you are running it, to help. For this reason: full path usually help – Giacomo Catenazzi Dec 06 '21 at 12:47
  • i am writing this two line code using spyder: – Sidra Rafique Dec 07 '21 at 00:37
  • import pickle as cPickle x = cPickle.load(open('c/Users/DELL/Desktop/data_preprocessed_python/data_preprocessed_python/s01.dat', 'rb')) – Sidra Rafique Dec 07 '21 at 00:38
  • i forgot to write : after c drive in full path. but still i am getting this error.UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 0: ordinal not in range(128) – Sidra Rafique Dec 07 '21 at 00:42
  • The last one is a different problem. Check the line where you get the error. It seems you are reading a file as ascii (and it is not ascii). It is preferable on every open (but the one with a 'b' mode as your pickle) to add explicitly a parameter `, encoding='utf-8'` (or `'latin1'`, or `'cp1252'`, or other less common encoding, depending on the origin of the data. See https://docs.python.org/3/library/codecs.html#standard-encodings) – Giacomo Catenazzi Dec 07 '21 at 08:01

0 Answers0