0
import seaborn as sns

flight_data = sns.load_dataset("flights")

When I try to get the dataset, the following error always occurs. It works well previously. I don' t know whether it is because of the net connection.

Traceback (most recent call last):

  File "D:\python程序\实习代码\运筹初探\torch_lstm.py", line 21, in <module>
    flight_data = sns.load_dataset("flights")

  File "D:\python\anaconda\anaconda\envs\pytorch-gpu\lib\site-packages\seaborn\utils.py", line 490, in load_dataset
    df = pd.read_csv(full_path, **kws)

  File "D:\python\anaconda\anaconda\envs\pytorch-gpu\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
    return func(*args, **kwargs)

  File "D:\python\anaconda\anaconda\envs\pytorch-gpu\lib\site-packages\pandas\io\parsers\readers.py", line 586, in read_csv
    return _read(filepath_or_buffer, kwds)

  File "D:\python\anaconda\anaconda\envs\pytorch-gpu\lib\site-packages\pandas\io\parsers\readers.py", line 482, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)

  File "D:\python\anaconda\anaconda\envs\pytorch-gpu\lib\site-packages\pandas\io\parsers\readers.py", line 811, in __init__
    self._engine = self._make_engine(self.engine)

  File "D:\python\anaconda\anaconda\envs\pytorch-gpu\lib\site-packages\pandas\io\parsers\readers.py", line 1040, in _make_engine
    return mapping[engine](self.f, **self.options)  # type: ignore[call-arg]

  File "D:\python\anaconda\anaconda\envs\pytorch-gpu\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 69, in __init__
    self._reader = parsers.TextReader(self.handles.handle, **kwds)

  File "pandas\_libs\parsers.pyx", line 542, in pandas._libs.parsers.TextReader.__cinit__

  File "pandas\_libs\parsers.pyx", line 642, in pandas._libs.parsers.TextReader._get_header

  File "pandas\_libs\parsers.pyx", line 843, in pandas._libs.parsers.TextReader._tokenize_rows

  File "pandas\_libs\parsers.pyx", line 1917, in pandas._libs.parsers.raise_parser_error

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 21: invalid continuation byte

Any help or advice would be appreciated!

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
zlq147
  • 1
  • 6
  • 2
    Have you had a look at [this](https://stackoverflow.com/questions/5552555/unicodedecodeerror-invalid-continuation-byte) or [that](https://stackoverflow.com/questions/30996289/utf8-codec-cant-decode-byte-0xf3) already? – iLuvLogix Sep 13 '21 at 13:59
  • You can try to specify `encoding`: `sns.load_dataset("flights", encoding='...')`, because `.load_csv` uses `pandas.read_csv`. – Trenton McKinney Sep 13 '21 at 23:46
  • Try updating seaborn. Go to the anaconda prompt, activate the pytorch-pgu environment and do `conda update --all`, though I doubt this will resolve it. – Trenton McKinney Sep 13 '21 at 23:50

0 Answers0