gpt4 book ai didi

python - 将列表转换为对角矩阵 DataFrame

转载 作者:太空宇宙 更新时间:2023-11-04 08:34:11 24 4
gpt4 key购买 nike

我以这种格式返回了一个元组列表:

[date1, date2, date3]
[ticker1, ticker2, ticker3]
[value1, value2, value3]

我想将它转换成一个 pandas 数据框,其中索引是日期,列是代码,数据是值。

最佳答案

使用枢轴

df=pd.DataFrame(lst).T
df.pivot(*df)

1 ticker1 ticker2 ticker3
0
date1 value1 None None
date2 None value2 None
date3 None None value3

关于python - 将列表转换为对角矩阵 DataFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50453073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com