我正在遍歷數(shù)據(jù)框并嘗試存儲每個 id 的“總”列表。數(shù)據(jù)框如下所示:id total difference 1 29 3 1 21 2 2 39 0 2 22 9到目前為止我嘗試過的:total_list=[]for i, row in df.iterrows(): total_list.extend(df.total.loc[df.id==row.id].tolist())print(total_list) # this never gets printtotal_list 應(yīng)該看起來像 [[29, 21], [39,22]]
Python - 嘗試存儲列表數(shù)組時陷入循環(huán)
慕桂英3389331
2021-07-21 17:05:26