使用forloop覆盖列表中的项目

我有这行有效的代码:

results_percentage = results_percentage.set_index('date').dropna(how='all').resample('M').last()

当我尝试使用 forloop 来完成同样的工作时,它不起作用。(我稍后需要使用 y ):

list_a = [ (results_percentage, "results_percentage")]
    for x, y in list_a :
    x = x.set_index('date').dropna(how='all').resample('M').last()


慕哥9229398
浏览 108回答 1
1回答

侃侃尔雅

您不是在更新对象,而是在创建一个新对象并将其分配给名为x, not的变量list_a[0][0]。用于inplace=True改变对象x.set_index('date', inplace=True) x.dropna(how='all', inplace=True)或者,您可以分配回列表for i, (x, y) in enumerate(list_a):      list_a[i] = (x.set_index('date').dropna(how='all'), y)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python