I have a list of DataFrames ie data = [df1,df2,df3.....dfn]. I am trying to iterate function maxloc through list of data and appending new values to new_max. It gives me following error 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:
for df in data:
# your loop
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.