Researcher at the Czech Academy of Sciences.
- Banach spaces and their operators; geometry of Banach spaces;
- Ideals and representations of operator algebras and, more generally, Banach algebras;
- Applied Probability, Financial markets, Python modelling.
import pandas as pd
Assuming df1 and df2 are your existing DataFrames
Merging df1 and df2 on GFCID and period
df_merged = pd.merge(df1, df2[['GFCID', 'period']], on=['GFCID', 'period'], how='left', indicator=True)
Adding the def_flag column based on the conditions
df1['def_flag'] = (
(df_merged['_merge'] == 'both') | # Condition 1: GFCID and period values match
(df1['ORR'].isin(["9", "9-", "10"])) | # Condition 2a: ORR is in the list ["9", "9-", "10"]
(df1['Baseline_ORR_orig'].isin(["9", "9-", "10"])) # Condition 2b: Baseline_ORR_orig is in the list ["9", "9-", "10"]
).astype(int)
Drop the temporary '_merge' column if needed
df_merged.drop(columns=['_merge'], inplace=True)
The final DataFrame df1 now contains the 'def_flag' column