从附加列表创建数据框(带日期时间)

Creating a Dataframe from an appended list (with datetime)

由于 API 限制,我将一长串仪器分批发送到 API,并将结果附加到 list。当我只使用 API 调用时,输出是一个我可以使用的数据框。然而,当我尝试分成批次并附加我的输出时,我无法弄清楚如何使它成为一个可行的数据框。

API 函数 (Pricegetter) 单独使用时会生成如下数据帧:

在以下代码中用作函数时,输出为 list(如下代码所示):

dict_list = ric_lists #ric_lists is list of ALL RICs
batch_list = []
return_list = []

for i in dict_list:
    batch_list.append(i)
    if len(batch_list)  == 5:
        return_list.append(Pricegetter(batch_list))
        batch_list.clear()

if batch_list:
    return_list.append(Pricegetter(batch_list))

输出列表:

[              KAER.VI
 2011-01-04  18.056605
 2011-01-05  18.056605
 2011-01-11  18.253407
 2011-01-12  18.253407
 2011-01-18  18.253407
 ...               ...
 2021-12-23  14.900000
 2021-12-27  15.100000
 2021-12-28  15.100000
 2021-12-29  15.200000
 2021-12-30  15.300000
 
 [1794 rows x 1 columns],
             BHAV.VI
 2011-01-03    43.05
 2011-01-07    43.01
 2011-01-11    43.00
 2011-01-19    43.05
 2011-01-20    43.05
 ...             ...
 2021-12-17    95.00
 2021-12-20    98.00
 2021-12-21    98.00
 2021-12-23    98.50
 2021-12-27    98.50
 
 [918 rows x 1 columns],
....]

如何将其转换为以日期为索引、以仪器名称为列 headers 的数据框,如示例图片所示?

尝试:

>>> pd.concat(return_list).sort_index()
              KAER.VI  DUEG.DE
2011-01-03        NaN   5.9250
2011-01-04  18.056605      NaN
2011-01-04        NaN   6.0600
2011-01-05  18.056605      NaN
2011-01-05        NaN   6.1400
2011-01-06        NaN   6.0650
2011-01-07        NaN   6.1375
2011-01-11  18.253407      NaN
2011-01-12  18.253407      NaN
2011-01-18  18.253407      NaN