Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

ErrorCorner

ErrorCorner Logo ErrorCorner Logo

ErrorCorner Navigation

  • Home
  • Contact Us
  • About Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Contact Us
  • About Us
Home/ Questions/Q 431
Next
Answered
Kenil Vasani
Kenil Vasani

Kenil Vasani

  • 646 Questions
  • 567 Answers
  • 77 Best Answers
  • 26 Points
View Profile
  • 3
Kenil Vasani
Asked: December 11, 20202020-12-11T20:36:38+00:00 2020-12-11T20:36:38+00:00In: Python

OSError: Initializing from file failed on csv in Pandas

  • 3

So far pandas read through all my CSV files without any problem, however now there seems to be a problem..

When doing:

df = pd.read_csv(r'path to file', sep=';')

I get:

OSError Traceback (most recent call
last) in ()
—-> 1 df = pd.read_csv(r’path
Übersicht\Input\test\test.csv’, sep=’;’)

c:\program files\python36\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)
703 skip_blank_lines=skip_blank_lines)
704
–> 705 return _read(filepath_or_buffer, kwds)
706
707 parser_f.name = name

c:\program files\python36\lib\site-packages\pandas\io\parsers.py in
_read(filepath_or_buffer, kwds)
443
444 # Create the parser.
–> 445 parser = TextFileReader(filepath_or_buffer, **kwds)
446
447 if chunksize or iterator:

c:\program files\python36\lib\site-packages\pandas\io\parsers.py in
init(self, f, engine, **kwds)
812 self.options[‘has_index_names’] = kwds[‘has_index_names’]
813
–> 814 self._make_engine(self.engine)
815
816 def close(self):

c:\program files\python36\lib\site-packages\pandas\io\parsers.py in
_make_engine(self, engine) 1043 def _make_engine(self, engine=’c’): 1044 if engine == ‘c’:
-> 1045 self._engine = CParserWrapper(self.f, **self.options) 1046 else: 1047 if engine == ‘python’:

c:\program files\python36\lib\site-packages\pandas\io\parsers.py in
init(self, src, **kwds) 1682 kwds[‘allow_leading_cols’] = self.index_col is not False 1683
-> 1684 self._reader = parsers.TextReader(src, **kwds) 1685 1686 # XXX

pandas_libs\parsers.pyx in
pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in
pandas._libs.parsers.TextReader._setup_parser_source()

OSError: Initializing from file failed

Other files in the same folder that are XLS files can be accessed without an issue.

When using the Python library like so:

import csv
file = csv.reader(open(r'pathtofile')) 

for row in file:
    print(row)
    break

df = pd.read_csv(file, sep=';')

the file is being loaded and the first line is printed. However I get:

ValueError: Invalid file path or buffer object type:

Probably because I can’t use read_csv this way…

How to get the first pandas function to work? The csv does not contain any special characters except German ones. The filesize is 10MB.

csvdataframepandaspython
  • 1 1 Answer
  • 9 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    1. Rohit Patel

      Rohit Patel

      • 0 Questions
      • 98 Answers
      • 0 Best Answers
      • 0 Points
      View Profile
      Best Answer
      Rohit Patel
      2020-12-11T20:35:26+00:00Added an answer on December 11, 2020 at 8:35 pm

      I ran into a similar problem. It turned out the CSV I had downloaded had no permissions at all. The error message from pandas did not point this out, making it hard to debug.

      Check that your file have read permissions

      • 8
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask A Question
    • Popular
    • Kenil Vasani

      SyntaxError: invalid syntax to repo init in the AOSP code

      • 5 Answers
    • Kenil Vasani

      xlrd.biffh.XLRDError: Excel xlsx file; not supported

      • 3 Answers
    • Kenil Vasani

      Homebrew fails on MacOS Big Sur

      • 3 Answers
    • Kenil Vasani

      runtimeError: package fails to pass a sanity check for numpy ...

      • 3 Answers
    • Kenil Vasani

      Unable to resolve dependency tree error when installing npm packages

      • 2 Answers

    Explore

    • Most Answered
    • Most Visited
    • Most Voted
    • Random

    © 2020-2021 ErrorCorner. All Rights Reserved
    by ErrorCorner.com