[Python] How to fix read_csv system error using pandas in python?

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am getting a system error when using pd.read_csv()

    import pandas as pd
    df = pd.read_csv('MLproject/color_names.csv', usecols=['Name', 'Hex'])
    print(df)


    The error I'm getting is:

    SystemError Traceback (most recent call last)
    Cell In[18], line 2
    1 import pandas as pd
    ----> 2 df = pd.read_csv('MLproject/color_names.csv', usecols=['Name', 'Hex'])
    3 print(df)

    File ~\AppData\Roaming\Python\Python312\site-packages\pandas\io\parsers\readers.py:1026, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)
    1013 kwds_defaults = _refine_defaults_read(
    1014 dialect,
    1015 delimiter,
    (...)
    1022 dtype_backend=dtype_backend,
    1023 )
    1024 kwds.update(kwds_defaults)
    -> 1026 return _read(filepath_or_buffer, kwds)

    File ~\AppData\Roaming\Python\Python312\site-packages\pandas\io\parsers\readers.py:620, in _read(filepath_or_buffer, kwds)
    617 _validate_names(kwds.get("names", None))
    619 # Create the parser.
    --> 620 parser = TextFileReader(filepath_or_buffer, **kwds)
    622 if chunksize or iterator:
    623 return parser

    File ~\AppData\Roaming\Python\Python312\site-packages\pandas\io\parsers\readers.py:1620, in TextFileReader.__init__(self, f, engine, **kwds)
    1617 self.options["has_index_names"] = kwds["has_index_names"]
    1619 self.handles: IOHandles | None = None
    -> 1620 self._engine = self._make_engine(f, self.engine)

    File ~\AppData\Roaming\Python\Python312\site-packages\pandas\io\parsers\readers.py:1898, in TextFileReader._make_engine(self, f, engine)
    1895 raise ValueError(msg)
    1897 try:
    -> 1898 return mapping[engine](f, **self.options)
    1899 except Exception:
    1900 if self.handles is not None:

    File ~\AppData\Roaming\Python\Python312\site-packages\pandas\io\parsers\c_parser_wrapper.py:61, in CParserWrapper.__init__(self, src, **kwds)
    60 def __init__(self, src: ReadCsvBuffer[str], **kwds) -> None:
    ---> 61 super().__init__(kwds)
    62 self.kwds = kwds
    63 kwds = kwds.copy()

    File ~\AppData\Roaming\Python\Python312\site-packages\pandas\io\parsers\base_parser.py:185, in ParserBase.__init__(self, kwds)
    181 self._name_processed = False
    183 self._first_chunk = True
    --> 185 self.usecols, self.usecols_dtype = self._validate_usecols_arg(kwds["usecols"])
    187 # Fallback to error to pass a sketchy test(test_override_set_noconvert_columns)
    188 # Normally, this arg would get pre-processed earlier on
    189 self.on_bad_lines = kwds.get("on_bad_lines", self.BadLineHandleMethod.ERROR)

    File ~\AppData\Roaming\Python\Python312\site-packages\pandas\io\parsers\base_parser.py:1026, in ParserBase._validate_usecols_arg(self, usecols)
    1020 if not is_list_like(usecols):
    1021 # see gh-20529
    1022 #
    1023 # Ensure it is iterable container but not string.
    1024 raise ValueError(msg)
    -> 1026 usecols_dtype = lib.infer_dtype(usecols, skipna=False)
    1028 if usecols_dtype not in ("empty", "integer", "string"):
    1029 raise ValueError(msg)

    File lib.pyx:1628, in pandas._libs.lib.infer_dtype()

    SystemError: ../numpy/_core/src/multiarray/iterators.c:192: bad argument to internal function


    This happened on its own, it worked litterally 30 mins ago and I didnt change nothing. Pls help, I have a demo today and cannot do it if this doesnt work. I tried reinstalling pandas and Numpy, installing Numpy 1.19.3, Changing usecols to [0,1]. Nothing works.

    Continue reading...

Compartilhe esta Página