类型错误:“列表”对象不可通过循环调用

时间:2020-03-28 01:07:38

标签: python pandas

这是我的代码:

"Create stateyear variable"

# Set index by taking out the Area Name column and moving it to the index (the rownames)
  d3 = d3.set_index('AreaName')
# Make a list of the values in the index (Area Name)
  states_list = d3.index.values
# Make a list of the years by dropping the FIPS column, looking at the remaining columns, and taking their values
years_list = d3.drop(['FIPS'], axis = 1).columns.values

# Make empty lists to populate for values and stateyear
values = []
stateyear = []
# Start the loop with the states
for states in states_list:
# Loop through the years
for years in years_list:
    # Append the value in the state and year to the values list
    values.append(d3.loc[states, years])
    # Turn the state and year into strings, paste them together, and append to the stateyear list
    stateyear.append(str(states) + '_' + str(years))

# Make a new dataframe called stateyear_values by combining the two lists
stateyear_values = pd.DataFrame(list(zip(values, stateyear)),
                            columns = ['amount', 'stateyear'])

错误消息:-------------------------------------------- ------------------------------- TypeError跟踪(最近一次通话) 在 9 10#通过合并两个列表来创建一个名为stateyear_values的新数据框 -> 11个stateyear_values = pd.DataFrame(list(zip(values,stateyear)), 12列= ['amount','stateyear']) 13

TypeError:“列表”对象不可调用

这是在一分钟前工作的,现在我知道'list'对象是不可调用的。请任何帮助表示赞赏!

0 个答案:

没有答案