Skip to content

Instantly share code, notes, and snippets.

@chronossc
Created August 31, 2017 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chronossc/bc8dfeb8a3286075b2f350f37a147148 to your computer and use it in GitHub Desktop.
Save chronossc/bc8dfeb8a3286075b2f350f37a147148 to your computer and use it in GitHub Desktop.
CSV to XLS with Pandas
import unicodecsv
from pandas import DataFrame
def csv_to_xls(fname, delimiter=';'):
with open(fname, 'r') as f:
stream = StringIO(f.read())
reader = unicodecsv.reader(stream, delimiter=delimiter)
df = DataFrame(list(reader))
with ExcelWriter(fname.replace('csv', 'xls')) as ew:
df.to_excel(ew, 'Sheet 1', index=False, header=False)
ew.save()
def run():
import os
files = os.listdir('.')
t = len(files)
for i, fname in enumerate(files, 1):
if os.path.splitext(fname)[-1] == '.csv' and fname.startswith('driver_'):
csv_to_xls(fname)
print "{} of {}".format(i, t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment