-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathexecel_to_csv.py
More file actions
22 lines (18 loc) · 859 Bytes
/
execel_to_csv.py
File metadata and controls
22 lines (18 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# -*- coding: utf-8 -*-
import os
import zipfile
import pandas as pd
from xlrd import open_workbook
dest_path = "/Users/zhulx/workspace/python/quant/data/ccs/"
for filename in os.listdir("/Users/zhulx/workspace/python/quant_data/ccs/"):
fullname = "/Users/zhulx/workspace/python/quant_data/ccs/" + filename
sheet_names = open_workbook(fullname).sheet_names()
for sheet_name in sheet_names:
data = pd.read_excel(fullname, sheet_name)
base_filename = dest_path + filename[:-5] + '_' + sheet_name
csv_filename = base_filename + ".csv"
data.to_csv(csv_filename, sep='\t', header=False, index=False, encoding='utf-8')
# zip_filename = base_filename + ".zip"
# ziphandler = zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED)
# ziphandler.write(csv_filename)
# ziphandler.close()