Pandas reports the following error when reading the file:
--------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-21-f8680ec116e3> in <module>()
1 #f = open(path)
----> 2 res = pd.read_csv('myfile.csv')
E:\anaconda_python\lib\site-packages\pandas\io\parsers.py 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)
644 skip_blank_lines=skip_blank_lines)
645
--> 646 return _read(filepath_or_buffer, kwds)
647
648 parser_f.__name__ = name
E:\anaconda_python\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
387
388 # Create the parser.
--> 389 parser = TextFileReader(filepath_or_buffer, **kwds)
390
391 if (nrows is not None) and (chunksize is not None):
E:\anaconda_python\lib\site-packages\pandas\io\parsers.py in __init__(self, f, engine, **kwds)
728 self.options['has_index_names'] = kwds['has_index_names']
729
--> 730 self._make_engine(self.engine)
731
732 def close(self):
E:\anaconda_python\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
921 def _make_engine(self, engine='c'):
922 if engine == 'c':
--> 923 self._engine = CParserWrapper(self.f, **self.options)
924 else:
925 if engine == 'python':
E:\anaconda_python\lib\site-packages\pandas\io\parsers.py in __init__(self, src, **kwds)
1388 kwds['allow_leading_cols'] = self.index_col is not False
1389
-> 1390 self._reader = _parser.TextReader(src, **kwds)
1391
1392 # XXX
pandas\parser.pyx in pandas.parser.TextReader.__cinit__ (pandas\parser.c:4184)()
pandas\parser.pyx in pandas.parser.TextReader._setup_parser_source (pandas\parser.c:8471)()
OSError: Initializing from file failed
When you use panda to read a file and report this error, it is usually because your file name contains Chinese, for example:
res = pd.read_csv('myfile.csv')
In this case, an error will be reported
f = open('myfile.csv')
res = pd.read_csv(f)
Then you can read the file
Similar Posts:
- Python pandas.read_ Oserror: initializing from file failed
- How to Solve ParserError: Error tokenizing data. C error: Expected 2 fields in line 53, saw 3
- [Solved] ModuleNotFoundError: No module named’usysconfigdata u x86 64-u-gnu’
- [Solved] UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa5 in position 1508: illegal multibyte sequence
- Python Pandas: Read_Excel() and to_Excel() function
- An error occurs when using PIP install XX command
- pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it’s not in you…
- Import pandas encountered no module named pandas in pychar
- Tensorflow error due to uninitialized variable [How to Fix]
- [Solved] Exception: Jupyter command `jupyter-notbook` not found.