python pandas - Editing multiple DataFrames with a for loop

前端 未结 6 740
误落风尘
误落风尘 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:02

    You can also do this by putting the dataframes into a dictionary:

    dfs = {
        'df0': df0,
        'df1': df1,
        'df2': df2
    }
    

    And then calling and assigning the contents of the dictionary in the for loop.

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

    This is useful if you can still want to call the dataframes by their name (instead of an arbitrary index in a list...)

    dfs['df0']
    

提交回复
热议问题