MCPcopy Index your code
hub / github.com/pathwaycom/pathway / consolidate

Function consolidate

python/pathway/tests/utils.py:911–933  ·  view source on GitHub ↗
(df: pd.DataFrame)

Source from the content-addressed store, hash-verified

909
910
911def consolidate(df: pd.DataFrame) -> pd.DataFrame:
912 values = None
913 for column in df.columns:
914 if column in ["time", "diff"]:
915 continue
916 if values is None:
917 values = df[column].astype(str)
918 else:
919 values = values + "," + df[column].astype(str)
920 df["_all_values"] = values
921
922 total = {}
923 for _, row in df.iterrows():
924 value = row["_all_values"]
925 if value not in total:
926 total[value] = 0
927 total[value] += row["diff"]
928
929 for i in range(df.shape[0]):
930 value = df.at[i, "_all_values"]
931 df.at[i, "diff"] = total[value]
932 total[value] = 0
933 return df[df["diff"] != 0].drop(columns=["_all_values"])
934
935
936def combine_columns(df: pd.DataFrame) -> pd.Series:

Callers 2

_assert_diffs_matchFunction · 0.90

Calls

no outgoing calls

Tested by 1

_assert_diffs_matchFunction · 0.72