Pandas does not find file

Asked

Viewed 773 times

-1

I am using pandas in Python to read a CSV file that is on my computer, however appears an error message, it seems that it does not find the file:

 import pandas as pd 

 reclamacoes = pd.read_csv("C:\Users\Reinaldo\Documents\Jornalismo_de_dados\Justica\reclamacoes\2017-1sem1.csv",sep=';')
IOErrorTraceback (most recent call last)
<ipython-input-4-685400fce544> in <module>()
----> 1 reclamacoes = pd.read_csv("C:\Users\Reinaldo\Documents\Jornalismo_de_dados\Justica\reclamacoes\2017-1sem1.csv",sep=';')

c:\cygwin64\home\reinaldo\code\justica\lib\site-packages\pandas\io\parsers.pyc

in parser_f(filepath_or_buffer, Sep, delimiter, header, Names, index_col, usecols, Squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, Compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision) 653 skip_blank_lines=skip_blank_lines) 654 --> 655 Return _read(filepath_or_buffer, kwds) 656 657 parser_f.name = name

c:\cygwin64\home\reinaldo\code\justica\lib\site-packages\pandas\io\parsers.pyc

in _read(filepath_or_buffer, kwds) 403 404 # Create the parser. --> 405 parser = Textfilereader(filepath_or_buffer, **kwds) 406 407 if chunksize or iterator:

c:\cygwin64\home\reinaldo\code\justica\lib\site-packages\pandas\io\parsers.pyc

in init(self, f, engine, **kwds) 762 self.options['has_index_names'] = kwds['has_index_names'] 763 --> 764 self. _make_engine(self.engine) 765 766 def close(self):

c:\cygwin64\home\reinaldo\code\justica\lib\site-packages\pandas\io\parsers.pyc

in _make_engine(self, engine) 983 def _make_engine(self, engine='c'): 984 if engine == 'c': --> 985 self. _engine = Cparserwrapper(self.f, **self.options) 986 987 if engine == 'python':

c:\cygwin64\home\reinaldo\code\justica\lib\site-packages\pandas\io\parsers.pyc

in init(self, src, **kwds) 1603 kwds['allow_leading_cols'] = self.index_col is not False 1604 -> 1605 self. _Reader = parsers.Textreader(src, **kwds) 1606 1607 # XXX

pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader.__cinit__

(pandas_libs parsers. c:4209)()

pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source

(pandas_libs parsers. c:8873)()

eclamacoes�7-1sem1.csv does not existnaldo\Documents\Jornalismo_de_dados\Justica

Does anyone know what it can be?

The file can be downloaded here: http://dados.gov.br/dataset/reclamacoes-do-consumidor-gov-br1/resource/1d0e048b-6a14-47e0-8145-3dace76185ed

3 answers

2


I’m a little rusty as Python, but I’m pretty sure \ (backslash) is used to "escape", if applicable switch to /, thus:

import pandas as pd 

reclamacoes = pd.read_csv("C:/Users/Reinaldo/Documents/Jornalismo_de_dados/Justica/reclamacoes/2017-1sem1.csv",sep=';')
  • 1

    @13dev, has nothing to do with windows or linux, almost all modern languages interpret / both on linux, Unix and windows.

1

Try To Add r at the beginning of the string:

import pandas as pd 
reclamacoes = pd.read_csv(r'C:\Users\Reinaldo\Documents\Jornalismo_de_dados\Justica\reclamacoes\2017-1sem1.csv',sep=';')

The r means Carriage Return.

The Carriage Return means return current line without go down. The name comes from the printer’s carriage, since the monitors were rare when the name was coined. This is commonly escaped as " r", abbreviated CR and has ASCII value 13 or 0x0D.

0

You can use the command pwd to find out where Jupyter Notebook is running.

By default, the system will fetch the file in this directory.

To read in a different folder, you need to put the " character.. " which server to read the file in a parent directory.

Example:

arquivo_text = pd.read_csv("../Subpasta1/Subpasta2/arquivo.csv", sep=';')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.