我是 python 新手,正在努力使用这个函数customer_state
。我有另一个函数可以从 csv 文件中获取数据。我想从该文件中获取一列的总和并得到sm1
(这给了我随时间 t(以天为单位)的增长率。这是我到目前为止所做的:
def del_pass():
reader = csv.DictReader(open("data.csv", "rb"))
all_rows = list()
for row in reader:
all_rows.append(row)
return all rows
def get_one_column(name):
column_list= list()
rows = del_pass()
for row in rows:
value = row(name)
if value =='':
value = 0
else:
value = int(value)
column_list.append(value)
return column_list
def customer_state(x):
sm = sum(x)
t = range(366)
sm1 = sm + (0.07 * (t/365) * sm)
return sm, sm1
def example_use1():
column_name ="totcust"
column = get_one_column(column_name)
column_stats = customer_state(column)
print column_stats
除了 之外,每个功能似乎都运行良好customer_state(x)
,这给了我以下错误。
sm1 = (sm + ((0.07/t) * sm))
TypeError: unsupported operand type(s) for /: 'float' and 'list'