gpt4 book ai didi

python - 旋转数据框后检索正常数据框

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:23 25 4
gpt4 key购买 nike

<分区>

我有一个 pandas 数据框,它是旋转的结果。它有多个索引。我想从这个旋转的 df 中得到一个“正常”的数据框......这样我就可以在新的 df 上做一些正常的操作。

这是一个示例:我的旋转数据框如下所示:

                      feature_value
feature_type f1 f2 f3 f4 f5
time name
2016-05-10 Clay 0 1 30 4 40
2016-05-10 John 0 4 10 4 66
2016-05-10 Mary 0 1 40 4 46
2016-05-10 Boby 2 0 30 4 59
2016-05-10 Lucy 5 8 20 4 41

以下是我想要的新 df:

time         name     f1  f2  f3  f4  f5
2016-05-10 Clay 0 1 30 4 40
2016-05-10 John 0 4 10 4 66
2016-05-10 Mary 0 1 40 4 46
2016-05-10 Boby 2 0 30 4 59
2016-05-10 Lucy 5 8 20 4 41

我该怎么做?

pivoted_df.to_dict() 看起来像这样:

{('feature_value', 'f1'): {(Timestamp('2016-05-10'), 'Clay'): 0, (Timestamp('2016-05-10'), 'John'): 0, (Timestamp('2016-05-10'), 'Mary'): 0, (Timestamp('2016-05-10'), 'Boby'): 2, (Timestamp('2016-05-10'), 'Lucy'): 5}, ('feature_value', 'f2'): {(Timestamp('2016-05-10'), 'Clay'): 1, (Timestamp('2016-05-10'), 'John'): 4, (Timestamp('2016-05-10'), 'Mary'): 1, (Timestamp('2016-05-10'), 'Boby'): 0, (Timestamp('2016-05-10'), 'Lucy'): 8}, ('feature_value', 'f3'): {(Timestamp('2016-05-10'), 'Clay'): 30, (Timestamp('2016-05-10'), 'John'): 10, (Timestamp('2016-05-10'), 'Mary'): 40, (Timestamp('2016-05-10'), 'Boby'): 30, (Timestamp('2016-05-10'), 'Lucy'): 20}, ('feature_value', 'f4'): {(Timestamp('2016-05-10'), 'Clay'): 4, (Timestamp('2016-05-10'), 'John'): 4, (Timestamp('2016-05-10'), 'Mary'): 4, (Timestamp('2016-05-10'), 'Boby'): 4, (Timestamp('2016-05-10'), 'Lucy'): 4}, ('feature_value', 'f5'): {(Timestamp('2016-05-10'), 'Clay'): 40, (Timestamp('2016-05-10'), 'John'): 66, (Timestamp('2016-05-10'), 'Mary'): 46, (Timestamp('2016-05-10'), 'Boby'): 59, (Timestamp('2016-05-10'), 'Lucy'): 41}}

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