Created
July 15, 2020 08:51
-
-
Save gautierdag/27b89d4914bb8bea14126a2efd773b21 to your computer and use it in GitHub Desktop.
Reduce 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
from functools import reduce | |
values = df.values | |
new_values = [] | |
cols = [df.columns.get_loc(d) for d in df.columns if d != "date"] | |
new_values.append(values[0]) | |
def compress_helper(x, y): | |
if (x[cols] == y[cols]).all(): | |
return x | |
new_values.append(y) | |
return y | |
reduce(compress_helper, values) | |
compressed_df = pd.DataFrame(data=new_values, columns=df.columns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment