XPMaster commited on
Commit
ecf5eaa
·
1 Parent(s): ab41066

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -74,12 +74,24 @@ def map_names(odf,fname):
74
  return mapped_frame,msg
75
 
76
  def get_lob(df):
77
- column_names = df.columns
78
- for pattern in ["lob", "market_segment", "product", "class_of_business",'type']:
79
- matching_columns = [col for col in column_names if pattern in col.lower()]
80
- if matching_columns:
81
- return sorted(matching_columns, key=len)[0]
82
- return None
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  def get_paid_amount(df):
85
  for col in df.columns:
 
74
  return mapped_frame,msg
75
 
76
  def get_lob(df):
77
+ global g_mapping
78
+ if g_mapping is None:
79
+ g_mapping = download_csv_as_dataframe('https://docs.google.com/spreadsheets/d/1rVoLrrTEDzU79x2H2Z1lJ7-z_jRbt-NMUdTarjLvSGo/edit?usp=drive_link')
80
+ mapping = g_mapping
81
+
82
+ column_names = set(df.columns)
83
+ best_match_col = None
84
+ max_matches = 0
85
+ for pattern in ["lob", "market_segment", "product", "class_of_business", 'type']:
86
+ matching_columns = {col for col in column_names if pattern in col.lower()}
87
+
88
+ for col in matching_columns:
89
+ matches = sum(df[col].isin(g_mapping['original']))
90
+ if matches > max_matches:
91
+ best_match_col = col
92
+ max_matches = matches
93
+ column_names -= matching_columns
94
+ return best_match_col if max_matches > 0 else None
95
 
96
  def get_paid_amount(df):
97
  for col in df.columns: