Created
September 26, 2018 19:13
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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