Skip to content

Instantly share code, notes, and snippets.

@gautierdag
Created July 15, 2020 08:51
Show Gist options
  • Save gautierdag/27b89d4914bb8bea14126a2efd773b21 to your computer and use it in GitHub Desktop.
Save gautierdag/27b89d4914bb8bea14126a2efd773b21 to your computer and use it in GitHub Desktop.
Reduce Date Compression
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