我对编码还很陌生,因此我确定可以使用更简单或更漂亮的方法来编写以下脚本。该脚本运行,并且在工作簿中创建了新工作表,但是,数据没有从“ sheet1”复制到第二个工作表
我已经尝试在Google堆栈溢出上搜索并阅读其他线程,但似乎没有一个答案
import os, csv, glob, shutil, pandas as pd, numpy as np, openpyxl as opyx
path_to_combined_file = c:\\somefilepath here\\
filepath = path_to_combined_file + 'NSW.xlsx'
unaided_brand_awareness = pd.read_excel(filepath)
from openpyxl import load_workbook
wb = load_workbook(filepath)
wb.create_sheet('unaided_brand_awareness')
wb.create_sheet('aided_brand_awareness')
wb.create_sheet('favourite_stations')
worksheet1 = wb['Sheet1']
worksheet2 = wb['unaided_brand_awareness']
for i in range (1,2000):
for j in range(1, worksheet1.max_column + 1):
worksheet2.cell(row = i, column = j).value = worksheet1.cell(row = i, column = j).value
wb.save(filepath)
代码应创建以下“无品牌知名度”,“辅助品牌知名度”和“喜爱的站点”表,然后将数据从“ Sheet1”表复制到“无品牌知名度”表
理想情况下,最好将“ Sheet1”中的数据复制到工作簿中的所有工作表中。
此外,我可能应该注意,“ Sheet1”中包含的单元格数量会因情况而异。