I am trying to delete the "std" sub-column from a multiindex DataFrame.
attribute attribute2 \
test1 std test2
d count type
r1 10 rx 0.559 (0.0) 0.559 (0.0) 0.568 (0.0)
sth1 0.653 (0.004) 0.653 (0.004) 0.679 (0.002)
sth2 0.584 (0.002) 0.584 (0.002) 0.586 (0.003)
sth3 0.651 (0.005) 0.651 (0.005) 0.676 (0
I can't seem to get my head around the pandas.MultiIndex.drop function.
The resulting dataframe should thus have only two mean columns, no "std"
How can this be done?
I think better is for remove all columns with std is second level of MultiIndex use drop with parameter level=1:
print (df)
attribute attribute2 attribute3
test1 std test2 std test3 std
d count type
r1 10 rx 0.559 (0.0) 0.559 (0.0) 0.568 (0.0)
sth1 0.653 (0.004) 0.653 (0.004) 0.679 (0.002)
sth2 0.584 (0.002) 0.584 (0.002) 0.586 (0.003)
sth3 0.651 (0.005) 0.651 (0.005) 0.676 (0)
df = df.drop('std', axis=1, level=1)
print (df)
attribute attribute2 attribute3
test1 test2 test3
d count type
r1 10 rx 0.559 0.559 0.568
sth1 0.653 0.653 0.679
sth2 0.584 0.584 0.586
sth3 0.651 0.651 0.676
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With