Python: How to turn a dictionary of Dataframes into one big dataframe with column names being the key of the previous dict?

前端 未结 3 1409
心在旅途
心在旅途 2021-02-04 02:19

So my dataframe is made from lots of individual excel files, each with the the date as their file name and the prices of the fruits on that day in the spreadsheet, so the spread

3条回答
  •  囚心锁ツ
    2021-02-04 02:25

    Something like this could work: loop over the dictionary, add the constant column with the dictionary key, concatenate and then set the date as index

    pd.concat(
        (i_value_df.assign(date=i_key) for i_key, i_value_df in d.items())
    ).set_index('date')
    

提交回复
热议问题