我目前正在尝试编写一个脚本,将.csv文件转换为.xlsx文件,然后对新文件进行一些数据分析。我正在尝试复制我制作的新文件时遇到错误。
这是错误:
File "C:/Users/mmunoz/Desktop/Excel Analysis/danielaScript1.0.py", line 40, in <module>
workbookCopy = xlutils.copy(workbook)
TypeError: 'module' object is not callable
这是我的原始代码
import os, csv
import glob
from openpyxl.cell import get_column_letter
from xlsxwriter.workbook import Workbook
import xlrd
import statistics as st
import xlutils.copy
position = []
load = []
positionMM = []
force = []
csvfile = input('Please input filename: ')
for csvfile in glob.glob(os.path.join('.', '*.csv')):
workbook = Workbook(csvfile + '.xlsx')
worksheet = workbook.add_worksheet()
with open(csvfile, 'r') as f:
reader = csv.reader(f)
for r, row in enumerate(reader):
for c, col in enumerate(row):
columb_letter = get_column_letter((c+1))
s = col
try:
s= float(s)
except ValueError:
pass
worksheet.write(r, c, s)
#%%
#workbook1 = xlrd.open_workbook(workbook)
workbookCopy = xlutils.copy(workbook)
sheet = workbook.sheet_by_index(0)
numRows = sheet.nrows
numCols = sheet.ncols
for row in range(2, numRows):
position.append(sheet.cell_value(row,2)) #appends values in column to position array
load.append(sheet.cell_value(row,3))#appends values in column to load array
答案 0 :(得分:0)
xlutils.copy是一个模块。
试试这个:
from xlutils.copy import copy
然后
workbookCopy = copy(workbook)