star_rating duration
Date 20170829 20170830 20170829 20170830
genre
Action 1038.1 1038.1 15917.0 16598.0
Adventure 595.0 595.0 9386.0 10113.0
Animation 490.7 490.7 5811.0 5989.0
Biography 596.9 596.9 9661.0 10002.0
Comedy 1211.7 1211.7 16616.0 16786.0
In[86]: df2.columns
Out[86]:
MultiIndex(levels=[['star_rating', 'duration'], [20170829, 20170830]],
labels=[[0, 0, 1, 1], [0, 1, 0, 1]],
names=[None, 'Date'])
Hi all, I have the above table df2 and I would like to insert a difference column which will be a simple subtraction of 20170830 - 20170829.
star_rating duration
Date 20170829 20170830 Diff 20170829 20170830 Diff
genre
Action 1038.1 1038.1 0 15917 16598 681
Adventure 595 595 0 9386 10113 727
Animation 490.7 490.7 0 5811 5989 178
Biography 596.9 596.9 0 9661 10002 341
Comedy 1211.7 1211.7 0 16616 16786 170
it would be easy if the date was at the very top in which case I can use df2['diff'] = df2[20170830] - df2[20170829]
.
I am new to multiIndex, so appreciate if anyone has any ideas to get me started. Thanks in advance.