From e179e62b9c0e643c65b0e6fdd843ba56fe216d8c Mon Sep 17 00:00:00 2001 From: Olexandr Balyk Date: Tue, 13 Feb 2024 19:29:19 -0500 Subject: [PATCH] Remove duplicate rows which differ only by description when printing to GAMS --- xl2times/__main__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xl2times/__main__.py b/xl2times/__main__.py index ceb2d67..0ca48d2 100644 --- a/xl2times/__main__.py +++ b/xl2times/__main__.py @@ -309,6 +309,10 @@ def write_dd_files( def convert_set(df: DataFrame): has_description = "TEXT" in df.columns + # Remove duplicate rows, ignoring text column + if has_description: + query_columns = [c for c in df.columns if c != "TEXT"] + df = df.drop_duplicates(subset=query_columns, keep="last") for row in df.itertuples(index=False): row_str = "'.'".join( (str(x) for k, x in row._asdict().items() if k != "TEXT")