I am working on a flat resale price dataset (In case you are interested, I am using the Jan 2015 onward data).
First, I group the data by using
data.groupby('flat_type').sum()
, Then the data becomes:
My attempt to swap rows
Now, I try to swap the last two rows by using the answer from this post:
b,c = data_by_type.iloc[-2], data_by_type.iloc[-1]
temp = data_by_type.iloc[-2].copy()
data_by_type.iloc[-2] = c
data_by_type.iloc[-1] = b
The content for the last two rows changed, but the index for the last two rows remains the same.
So my question is: How to swap the entire row, including the index?