Python 使用forloop覆盖列表中的项

Python 使用forloop覆盖列表中的项,python,python-3.x,pandas,list,for-loop,Python,Python 3.x,Pandas,List,For Loop,我有这样一行代码: results_percentage = results_percentage.set_index('date').dropna(how='all').resample('M').last() 当我尝试forloop做同样的工作时,它不起作用。(我以后需要使用y): 您不是在更新对象,而是在创建一个新对象并将其分配给名为x的变量,而不是list\u a[0][0] 使用inplace=True修改对象 x.set\u索引('date',inplace=True) x、 dr

我有这样一行代码:

results_percentage = results_percentage.set_index('date').dropna(how='all').resample('M').last()
当我尝试forloop做同样的工作时,它不起作用。(我以后需要使用y):


您不是在更新对象,而是在创建一个新对象并将其分配给名为
x
的变量,而不是
list\u a[0][0]

使用
inplace=True
修改对象

x.set\u索引('date',inplace=True)
x、 dropna(how='all',inplace=True)
或者,您可以重新分配给列表

枚举(列表a)中i,(x,y)的
:
列表a[i]=(x.set索引('date').dropna(how='all'),y)

您需要
删除重复项
来删除重复项我已经修改了问题,如果我正在重新采样,我该怎么做<代码>x.resample('W',inplace=True)。last()
list_a = [ (results_percentage, "results_percentage")]

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