Skip to content

Instantly share code, notes, and snippets.

@daybreak0804
Created March 20, 2016 11:23
Show Gist options
  • Save daybreak0804/cb7ca95bb075fc9e82e3 to your computer and use it in GitHub Desktop.
Save daybreak0804/cb7ca95bb075fc9e82e3 to your computer and use it in GitHub Desktop.
# part 1
import openpyxl
import pandas as pd
import numpy as np
workbook1 = openpyxl.load_workbook('ExcelPowerQueryConsumePredict.xlsx')
sheet = workbook1.get_sheet_by_name('AAA')
csv_AAA = pd.read_csv('AAA.csv', header=None)
row_length = csv_AAA.shape[0]
column_length = csv_AAA.shape[1]
#part 2
for r in range(1, row_length+1):
for c in range(1, column_length+1):
if type(csv_AAA.iloc[r-1, c-1]) == np.int64:
data = csv_AAA.iloc[r-1, c-1].astype(np.int)
elif type(csv_AAA.iloc[r-1, c-1]) == np.float64 or type(csv_AAA.iloc[r-1, c-1]) == np.float32:
data = csv_AAA.iloc[r-1, c-1].astype(np.float)
else:
data = csv_AAA.iloc[r-1, c-1]
sheet.cell(row=r, column=c).value = data
#part 3
workbook1.save('C:\\Users\\user\\Desktop\\pythonCodes\\testResult.xlsx')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment