我有這行有效的代碼: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()
1 回答

侃侃爾雅
TA貢獻1801條經驗 獲得超16個贊
您不是在更新對象,而是在創建一個新對象并將其分配給名為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)
添加回答
舉報
0/150
提交
取消