def csv_to_xlsx(filename):
import pandas as pd
import os
pd.read_csv('xlsx/' + filename + '.csv', sep=",", encoding="cp1251").to_excel('xlsx/' + filename + '.xlsx', index=None)
os.remove('xlsx/' + filename + '.csv')
Traceback (most recent call last):
File "C:\Users\PycharmProjects\xl\drom\main.py", line 89, in
get_mail()
File "C:\Users\PycharmProjects\xl\drom\main.py", line 46, in get_mail
mails = get_file('febest', mails, part, ms[c])
File "C:\Users\PycharmProjects\xl\drom\main.py", line 68, in get_file
csv_to_xlsx(company + str(c))
File "C:\Users\PycharmProjects\xl\drom\main.py", line 85, in csv_to_xlsx
pd.read_csv('drom/xlsx/' + filename + '.csv', sep=",", encoding="cp1251").to_excel('drom/xlsx/' + filename + '.xlsx', index=None)
File "C:\Users\PycharmProjects\xl\venv\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "C:\Users\PycharmProjects\xl\venv\lib\site-packages\pandas\io\parsers\readers.py", line 680, in read_csv
return _read(filepath_or_buffer, kwds)
File "C:\Users\PycharmProjects\xl\venv\lib\site-packages\pandas\io\parsers\readers.py", line 581, in _read
return parser.read(nrows)
File "C:\Users\PycharmProjects\xl\venv\lib\site-packages\pandas\io\parsers\readers.py", line 1255, in read
index, columns, col_dict = self._engine.read(nrows)
File "C:\Users\PycharmProjects\xl\venv\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 225, in read
chunks = self._reader.read_low_memory(nrows)
File "pandas\_libs\parsers.pyx", line 805, in pandas._libs.parsers.TextReader.read_low_memory
File "pandas\_libs\parsers.pyx", line 861, in pandas._libs.parsers.TextReader._read_rows
File "pandas\_libs\parsers.pyx", line 847, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas\_libs\parsers.pyx", line 1960, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 8 fields in line 3, saw 10
filename=...
pandas.read_csv('c:\\work\\' + filename + '.csv', sep=";", encoding="utf8").to_excel('c:\\work\\' + filename + '.xlsx', index=None)
import os
import glob
import csv
from xlsxwriter.workbook import Workbook
for csvfile in glob.glob(os.path.join('.', '*.csv')):
workbook = Workbook(csvfile[:-4] + '.xlsx')
worksheet = workbook.add_worksheet()
with open(csvfile, 'rt', encoding='utf8') as f:
reader = csv.reader(f)
for r, row in enumerate(reader):
for c, col in enumerate(row):
worksheet.write(r, c, col)
workbook.close()