Created
July 15, 2020 08:49
-
-
Save gautierdag/65df852191069121b6a49fdf5aa19fed to your computer and use it in GitHub Desktop.
Naive Date Compression
This file contains 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
# set first (oldest balance as index entry) | |
new_indexes = [0] | |
# choose columns that are not the date column | |
cols = [d for d in df.columns if d != "date"] | |
# iterate over rows | |
for i, row in df.iterrows(): | |
if i == 0: #skip 0 index since it has no previous balance | |
continue | |
# if not all values of the previous row/date is not equal to current - then we have new observation | |
if not (df.iloc[i-1][cols] ==row[cols]).all(): | |
new_indexes.append(i) | |
#select new df based on indexes | |
compressed_df = df.loc[new_indexes].reset_index(drop=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment