[英]How to iterate a function through a list of dataframe in python 3.7
I have a list of DataFrames ie data = [df1,df2,df3.....dfn].我有一个 DataFrames 列表,即 data = [df1,df2,df3.....dfn]。 I am trying to iterate function maxloc through list of data and appending new values to new_max.
我正在尝试通过数据列表迭代 function maxloc 并将新值附加到 new_max。 It gives me following error TypeError: 'int' object is not iterable.
它给了我以下错误 TypeError: 'int' object is not iterable。 How can I fix it?
我该如何解决?
def max(data):
data['loc_max'] = np.zeros(len(data))
for i in range(1,len(data)-1):
if data['value'][i] >= data['value'][i-1] and data['value'][i] >= data['value'][i+1]:
data['loc_max'][i] = 1
return data
def maxloc(data):
loc_opt_ind = argrelextrema(df['values'].values, np.greater)
loc_max = np.zeros(len(data))
loc_max[loc_opt_ind] = 1
data['loc_max'] = loc_max
return data
new_max= []
for df in range(len(data)):
max_values = maxloc(df).loc_max
new_max.append(max_values)
When you use:当您使用:
for df in range(len(data)):
# your loop
your df is just intgers, you should use this loop instea:你的 df 只是整数,你应该使用这个循环 instea:
for df in data:
# your loop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.