我有一个错误,当我想从我的驱动器导入我的数据到colab
.如果有人知道为什么我会很高兴知道.这里是代码:
import pandas as pd
from google.colab import drive
drive.mount('/content/drive')
Webshop_train_2023 = pd.read_csv("/content/drive/MyDrive/Thierry /Titi /Webshop_train_2023.csv")
错误:
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-12-7276aceb36b1> in <cell line: 1>()
----> 1 Webshop_train_2023 = pd.read_csv("/content/drive/MyDrive/Thierry /Titi /Webshop_train_2023.csv")
9 frames
/usr/local/lib/python3.9/dist-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
309 stacklevel=stacklevel,
310 )
--> 311 return func(*args, **kwargs)
312
313 return wrapper
/usr/local/lib/python3.9/dist-packages/pandas/io/parsers/readers.py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, 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, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
676 kwds.update(kwds_defaults)
677
--> 678 return _read(filepath_or_buffer, kwds)
679
680
/usr/local/lib/python3.9/dist-packages/pandas/io/parsers/readers.py in _read(filepath_or_buffer, kwds)
573
574 # Create the parser.
--> 575 parser = TextFileReader(filepath_or_buffer, **kwds)
576
577 if chunksize or iterator:
/usr/local/lib/python3.9/dist-packages/pandas/io/parsers/readers.py in __init__(self, f, engine, **kwds)
930
931 self.handles: IOHandles | None = None
--> 932 self._engine = self._make_engine(f, self.engine)
933
934 def close(self):
/usr/local/lib/python3.9/dist-packages/pandas/io/parsers/readers.py in _make_engine(self, f, engine)
1232
1233 try:
-> 1234 return mapping[engine](f, **self.options)
1235 except Exception:
1236 if self.handles is not None:
/usr/local/lib/python3.9/dist-packages/pandas/io/parsers/c_parser_wrapper.py in __init__(self, src, **kwds)
73
74 kwds["dtype"] = ensure_dtype_objs(kwds.get("dtype", None))
---> 75 self._reader = parsers.TextReader(src, **kwds)
76
77 self.unnamed_cols = self._reader.unnamed_cols
/usr/local/lib/python3.9/dist-packages/pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()
/usr/local/lib/python3.9/dist-packages/pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._get_header()
/usr/local/lib/python3.9/dist-packages/pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows()
/usr/local/lib/python3.9/dist-packages/pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 2786: invalid continuation byte
没有试过这么多
1条答案
按热度按时间iq0todco1#
问题是编码,我假设你的csv文件有英语以外的语言。
尝试
或
或者如果你知道用哪个编码器来解码语言,把“utf-8”改成那个。