0

I'm attempting to try a t-test in python using the pandas module. However, the same error keeps occuring in which my target file cannot be found. In this case, the target file is brain_size.csv, where the separators are semi-colons. The values which are left blank are represented by a period.

Here's what I have keyed in:

import pandas as pd
data = pd.read_csv('This PC\Desktop\brain_size.csv', sep=';', na_values='.')

Here's the error message. It's a long string

File "C:\Users\Tina Gnali\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 562, in parser_f
  return _read(filepath_or_buffer, kwds)
  File "C:\Users\Tina Gnali\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 315, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "C:\Users\Tina Gnali\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 645, in __init__
    self._make_engine(self.engine)
  File "C:\Users\Tina Gnali\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 799, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "C:\Users\Tina Gnali\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1213, in __init__
    self._reader = _parser.TextReader(src, **kwds)
  File "pandas\parser.pyx", line 358, in pandas.parser.TextReader.__cinit__ (pandas\parser.c:3427)
  File "pandas\parser.pyx", line 628, in pandas.parser.TextReader._setup_parser_source (pandas\parser.c:6861)
OSError: File b'This PC\\Desktop\x08rain_size.csv' does not exist
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

I want to ask:

  1. What am I doing wrong? Why I can't retrieve the target file?

  2. Why my error elicits such a long error message?

  3. What does the "parser" module do?

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43
Maurice1016
  • 3
  • 1
  • 2

3 Answers3

1

The problem is with using backslashes "\". You must avoid that. Backslash is reserved for something called escape characters, like new line being denoted with "\n" and stuff. Either use double backslashes "\\" or just forwardslashes "/" or raw literals in your read_csv():

"C:\\Users\\blabla\\"

or

"C:/Users/blabla/"

or

r"C:\Users\blabla\"

Regarding how to identify the error, look for the "error" string in the error message. It is here:

OSError: File b'This PC\\Desktop\x08rain_size.csv' does not exist

This tells you that Python is looking for a file called 'x08rain_size.csv', and obviously you don't have such a file. But what is x08rain? Could it be that b is replaced with x08 when you place a backslash in front of it? Let's ask this to Python:

In [247]: '\b'
Out[247]: '\x08'

There we go!

FatihAkici
  • 4,679
  • 2
  • 31
  • 48
0

Sometimes you may not be able to use

"C:\\Users\\blabla\\" or "C:/Users/blabla/"

Solution 1. The other option could be this: Open Anaconda prompt or cmd, then change the path. Lets assume you are in drive "c" and your folder is in drive e. So after opening the cmd write "e:" and hit enter. Then the command will show you "E:\>". Now you should write "cd E:\Users\blabla\desired_folder". After running that, you should write "jupyter notebook" and run it. It will generate and open a new notebook in the same folder that has your file.

Solution 2. The other simple solution is, after opening the jupyther notebook> file> use the folder icon and choose the right folder.

Ali
  • 2,702
  • 3
  • 32
  • 54
-1

May be the sep is different it may be "," try it and if still it doesnt works try removing sep and na values and try to keep the file in same directory where the program is present or give actual path