I need to get a DataFrame with column difference of column that I choose (for example the last one)
I tried using df.diff(axis=1, periods=1) will count column difference with the next column. However, I want to get difference of columns with exactly one column (last one).
>Solution :
Use DataFrame.sub for subtract by last column selected by DataFrame.iloc:
df1 = df.sub(df.iloc[:, -1], axis=0)
If need subtract by column selected by label:
df1 = df.sub(df['col'], axis=0)