Сам код:
import os
def csv_to_xlsx(path, filename, ex):
import pandas as pd
pd.read_csv(path + filename, encoding='utf-8', sep=";").to_excel(
path + f'auto-ms{ex}.xlsx', index=None)
os.remove(path + filename)
Ошибка:
Traceback (most recent call last):
File "C:\Users\Danil\PycharmProjects\mail\main.py", line 45, in
ms_attachments(msg, path, '_khb')
File "C:\Users\Danil\PycharmProjects\mail\prods\auto_ms.py", line 34, in ms_attachments
csv_to_xlsx(path, f'auto-ms{ex}.csv', ex)
File "C:\Users\Danil\PycharmProjects\mail\prods\auto_ms.py", line 4, in csv_to_xlsx
pd.read_csv(path + filename, encoding='utf-8', sep=";").to_excel(
File "C:\Users\Danil\PycharmProjects\mail\venv\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "C:\Users\Danil\PycharmProjects\mail\venv\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
File "C:\Users\Danil\PycharmProjects\mail\venv\lib\site-packages\pandas\io\parsers\readers.py", line 950, in read_csv
return _read(filepath_or_buffer, kwds)
File "C:\Users\Danil\PycharmProjects\mail\venv\lib\site-packages\pandas\io\parsers\readers.py", line 605, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\Danil\PycharmProjects\mail\venv\lib\site-packages\pandas\io\parsers\readers.py", line 1442, in __init__
self._engine = self._make_engine(f, self.engine)
File "C:\Users\Danil\PycharmProjects\mail\venv\lib\site-packages\pandas\io\parsers\readers.py", line 1753, in _make_engine
return mapping[engine](f, **self.options)
File "C:\Users\Danil\PycharmProjects\mail\venv\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 79, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas\_libs\parsers.pyx", line 547, in pandas._libs.parsers.TextReader.__cinit__
File "pandas\_libs\parsers.pyx", line 664, in pandas._libs.parsers.TextReader._get_header
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 0: invalid start byte