[英]converting/analyzing .csv to xlsx file
I am currently attempting to write a script that converts a .csv file to a .xlsx file, then do some data analysis on the new file. 我目前正在尝试编写将.csv文件转换为.xlsx文件的脚本,然后对新文件进行一些数据分析。 I am currently running into an error when trying to copy the new file i make.
尝试复制我制作的新文件时,我当前遇到错误。
here is the error: 这是错误:
File "C:/Users/mmunoz/Desktop/Excel Analysis/danielaScript1.0.py", line 40, in <module>
workbookCopy = xlutils.copy(workbook)
TypeError: 'module' object is not callable
Here is my original code 这是我的原始代码
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
xlutils.copy is a module. xlutils.copy是一个模块。
Try this: 尝试这个:
from xlutils.copy import copy
then 然后
workbookCopy = copy(workbook)
More info: http://xlutils.readthedocs.io/en/latest/copy.html 更多信息: http : //xlutils.readthedocs.io/en/latest/copy.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.