Sfoglia il codice sorgente

Add method used when calculating ihs values

ogert 4 anni fa
parent
commit
0fbab3b325
1 ha cambiato i file con 35 aggiunte e 0 eliminazioni
  1. 35 0
      cdplib/db_migration/MigrationCleaning.py

+ 35 - 0
cdplib/db_migration/MigrationCleaning.py

@@ -638,6 +638,41 @@ class MigrationCleaning:
 
         return data
 
+
+    def label_is_level(
+                    self,
+                    data: pd.DataFrame, 
+                    column: str = "is", 
+                    include_schrott: bool = False, 
+                    drop_rows_with_no_is: bool = False) -> pd.DataFrame:
+        '''
+        '''
+
+        is_level_mapping = {0: None,
+                            1: ["IS1"],
+                            2: ["IS1L", "IL", "IS1 + IL"],
+                            3: ["IS2"],
+                            4: ["IS3"]}
+
+        for k, v in is_level_mapping.items():
+            if v is not None:
+                data.loc[data[column].isin(v), column] = k
+            else:
+                data.loc[data[column].isnull(), column] = k
+        
+        if include_schrott and ("operation_type_2" in data.columns):
+            schrott_mask = (data["operation_type_2"] == 2)
+            data.loc[schrott_mask, column] = 5
+        
+        data.loc[~data[column].isin([0,1,2,3,4,5]), column] = 0
+                    
+        if drop_rows_with_no_is:
+            data = data.loc[data[column] != 0].copy(deep=True)
+            
+        return data.reset_index(drop=True)
+
+
+
 if __name__ == "__main__":
 
     # testing