gpt4 book ai didi

python - 将 pandas MultiIndex 级别更改为 '+1'

转载 作者:太空宇宙 更新时间:2023-11-03 15:12:12 24 4
gpt4 key购买 nike

如何重命名 MultiIndex level = 0,如 this_df 中所述就像'ti'->'ti+1'?

this_df 包含使用 ti 数据计算 ti+1 中的加权和的归一化权重。

this_df = pd.read_csv('http://www.boomboxbooking.de/stackq/data.csv', index_col =[0,1], sep=';')

new_index_level_0 = ['t1','t2','t3']

最佳答案

使用set_levelsIndex 对象上分配新值:

In[72]:
this_df.index = this_df.index.set_levels(['t1','t2','t3'], 0)
this_df

Out[72]:
earnings costs
Unnamed: 1
t1 S1 0.50 0.50
S2 0.50 0.50
t2 S1 0.20 0.09
S2 0.80 0.91
t3 S1 0.43 0.20
S2 0.57 0.80

关于python - 将 pandas MultiIndex 级别更改为 '+1',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44135030/

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