[英]Repeated datetime index pandas
I have a dataframe with multiple datetime index like 我有一个具有多个日期时间索引的数据框,例如
I would like to split data_value_index into three columns with the same index. 我想将data_value_index分为具有相同索引的三列。 So far I have only separated the dataframe and merge it like
到目前为止,我只分离了数据框并将其合并
df1= df[df['data_value_index']==5]
df2= df[df['data_value_index']==9]
df3 = df[df['data_value_index']==14]
df=pd.merge(df1,df2,left_index=True,right_index=True)
Is there any simpler way to do it? 有没有更简单的方法可以做到这一点?
似乎您需要新密钥的cumcount
,然后再cumcount
unstack
df.set_index(df.groupby(df.index).cumcount(),append=True)['data_value_index'].unstack()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.