Created
August 31, 2017 18:54
-
-
Save felipe-prenholato/bc8dfeb8a3286075b2f350f37a147148 to your computer and use it in GitHub Desktop.
CSV to XLS with Pandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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