Hi I have a dataframe that has several columns in it. Id like to either create a new dataframe or replace the columns in this dataframe between Timestamp
to y_pred
with the difference of that column but i'd like the final result to maintain the same order. So CLES12Z would be replaced by the diff of the previous CLES12Z row and the current CLES12Z row and that would be carried out for every column up to y_pred.
So far I've tried the following:
columnend = data.columns.get_loc('y_pred')
for e, col in enumerate(data.columns):
if e < columnend and (e>0):
print(col)
data[col+'Diff'] = data[col]-data[col].shift(1)
data.drop([col],axis=1,inplace=True)
But I'm noticing that will just put all the new columns to the end and Id then have to resort the entire dataframe.
I was wondering if there was a more direct or effecient way to do this?