Skip to content

Instantly share code, notes, and snippets.

@jplsightm
Created September 26, 2018 19:13
Show Gist options
  • Save jplsightm/03ae3adf36ff625bfd8b7907857a3f66 to your computer and use it in GitHub Desktop.
Save jplsightm/03ae3adf36ff625bfd8b7907857a3f66 to your computer and use it in GitHub Desktop.
Sometimes you just need to shift items back in a dataframe (typically with times series data). This is a hackish way to do that :) Enjoy
import pandas as pd
def step_back_ts(frame, ts_col, shift):
timestamps = pd.DataFrame(frame[ts_col].iloc[shift:], columns=['timestamp'])
timestamps.reset_index(inplace=True, drop=True)
for i in range(shift):
timestamps.loc[len(timestamps)+1, 'timestamp'] = np.nan
return timestamps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment