且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用插值填充多索引Pandas DataFrame

更新时间:2022-11-14 09:06:22

我将尝试在索引的OptionType级别上拆栈数据框.

I'd try to unstack the data frame at the OptionType level of index.

df.unstack(level=1)

这样,您应该获得一个索引数据帧,它将调用和放置类别都移动到列中.也许这不是解决问题的最优雅的方法,但是它应该可以解决问题,而不会让put/call罢工重叠.

This way you should obtain a single index dataframe which will have both call and put categories moved to columns. Maybe it's not the most elegant way of solving the problem, but it should work things out, not letting the put/call strikes to overlap.

如果多索引df是进行进一步计算的最理想方法,则可以使用堆栈方法恢复原始格式.

If multi index df is the most desirable one for further computations, you can restore the original format using stack method.