python pandas - Editing multiple DataFrames with a for loop

前端 未结 6 768
误落风尘
误落风尘 2021-01-06 18:30

Considering the following 2 lists of 3 dicts and 3 empty DataFrames

dict0={\'actual\': {\'2013-02-20 13:30:00\': 0.93}}
dict1={\'actual\': {\'2013-02-20 13:3         


        
6条回答
  •  温柔的废话
    2021-01-06 19:24

    In your loop, df is just a temporary value, not a reference to the corresponding list element. If you want to modify the list while iterating it, you have to reference the list by index. You can do that using Python's enumerate:

    for i, (df, dikt) in enumerate(zip(dfs, dicts)):
        dfs[i] = df.from_dict(dikt, orient='columns', dtype=None)
    

提交回复
热议问题