bugfix
This commit is contained in:
@@ -9020,24 +9020,24 @@ class DataProcessor:
|
||||
# +++ NEUER BLOCK: Erstellung des 'is_part_of_group' Features +++++++++++++
|
||||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
self.logger.info("Erstelle Feature 'is_part_of_group'...")
|
||||
# Sicherstellen, dass die Spalten als String behandelt werden und NaNs/Leerstrings korrekt ausgewertet werden
|
||||
|
||||
# Zugreifen auf die Spalten im DataFrame df_subset
|
||||
# Die Spaltennamen hier müssen den internen Namen entsprechen,
|
||||
# die in col_keys_mapping definiert wurden (z.B. 'parent_d_raw').
|
||||
parent_d_series = df_subset['parent_d_raw'].astype(str).str.strip().str.lower()
|
||||
parent_o_series = df_subset['parent_o_raw'].astype(str).str.strip().str.lower()
|
||||
parent_p_series = df_subset['parent_p_raw'].astype(str).str.strip().str.lower()
|
||||
|
||||
# Bedingung 1: Parent D ist gefüllt und nicht 'k.a.'
|
||||
cond1 = parent_d_series.notna() & (parent_d_series != 'k.a.') & (parent_d_series != '')
|
||||
|
||||
# Bedingung 2: Parent O ist gefüllt und nicht 'k.a.' UND Parent P Status ist 'x'
|
||||
cond2_o = parent_o_series.notna() & (parent_o_series != 'k.a.') & (parent_o_series != '')
|
||||
cond2_p = parent_p_series == 'x' # 'x' für akzeptiert
|
||||
cond2_p = parent_p_series == 'x'
|
||||
cond2 = cond2_o & cond2_p
|
||||
|
||||
df_subset['is_part_of_group'] = np.where(cond1 | cond2, 1, 0)
|
||||
# .loc verwenden, um die neue Spalte sicher zuzuweisen und SettingWithCopyWarning zu vermeiden
|
||||
df_subset.loc[:, 'is_part_of_group'] = np.where(cond1 | cond2, 1, 0)
|
||||
|
||||
self.logger.info(f"Feature 'is_part_of_group' erstellt. {df_subset['is_part_of_group'].sum()} Unternehmen als Teil einer Gruppe markiert.")
|
||||
# Überprüfen Sie die Verteilung, um sicherzustellen, dass es nicht nur Nullen oder Einsen sind
|
||||
self.logger.debug(f"Verteilung von 'is_part_of_group':\n{df_subset['is_part_of_group'].value_counts(normalize=True)}")
|
||||
self.logger.debug(f"Verteilung von 'is_part_of_group':\n{df_subset['is_part_of_group'].value_counts(normalize=True, dropna=False)}")
|
||||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
# +++ ENDE NEUER BLOCK ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
Reference in New Issue
Block a user