重塑数据框以与另一个数据框具有相同的索引
Reshape dataframe to have the same index as another dataframe
我有两个数据框:
dayData
power_comparison final_average_delta_power calculated_power
1 0.0 0.0 0
2 0.0 0.0 0
3 0.0 0.0 0
4 0.0 0.0 0
5 0.0 0.0 0
7 0.0 0.0 0
和
historicPower
power
0 0.0
1 0.0
2 0.0
3 -1.0
4 0.0
5 1.0
7 0.0
我正在尝试重新索引 historicPower
数据框,使其具有与 dayData
数据框相同的形状(所以在这个例子中它看起来像):
power
1 0.0
2 0.0
3 -1.0
4 0.0
5 1.0
7 0.0
现实中的dataframes会大很多,形状各异。
如果 index
没有重复,我想你可以使用 reindex
:
historicPower = historicPower.reindex(dayData.index)
print (historicPower)
power
1 0.0
2 0.0
3 -1.0
4 0.0
5 1.0
7 0.0
我有两个数据框:
dayData
power_comparison final_average_delta_power calculated_power
1 0.0 0.0 0
2 0.0 0.0 0
3 0.0 0.0 0
4 0.0 0.0 0
5 0.0 0.0 0
7 0.0 0.0 0
和
historicPower
power
0 0.0
1 0.0
2 0.0
3 -1.0
4 0.0
5 1.0
7 0.0
我正在尝试重新索引 historicPower
数据框,使其具有与 dayData
数据框相同的形状(所以在这个例子中它看起来像):
power
1 0.0
2 0.0
3 -1.0
4 0.0
5 1.0
7 0.0
现实中的dataframes会大很多,形状各异。
如果 index
没有重复,我想你可以使用 reindex
:
historicPower = historicPower.reindex(dayData.index)
print (historicPower)
power
1 0.0
2 0.0
3 -1.0
4 0.0
5 1.0
7 0.0