Skip to content

Instantly share code, notes, and snippets.

@tengpeng
Created October 28, 2016 03:52
Show Gist options
  • Save tengpeng/83d66ff05911460b4f5d80c475dee920 to your computer and use it in GitHub Desktop.
Save tengpeng/83d66ff05911460b4f5d80c475dee920 to your computer and use it in GitHub Desktop.
Skip header of Excel file
# coding: utf-8
# In[1]:
import openpyxl
import csv
# In[2]:
wb = openpyxl.load_workbook('disaggreation_data.xlsx')
# In[12]:
for sheet_name in wb.get_sheet_names():
sheet = wb.get_sheet_by_name(sheet_name)
col1 = []
cnt = 1
for i in sheet['A']:
if cnt <= 6:
cnt += 1
continue
col1.append(str(i.value).split(' ')[0])
col2 = []
cnt = 1
for i in sheet['B']:
if cnt <= 6:
cnt += 1
continue
col2.append(i.value)
data = zip(col1, col2)
with open(str(sheet_name)+'.csv','wb') as out:
csv_out=csv.writer(out)
for row in data:
csv_out.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment