Skip to main content
Tomasz Kania's user avatar
Tomasz Kania's user avatar
Tomasz Kania's user avatar
Tomasz Kania
  • Member for 12 years, 11 months
  • Last seen this week
Stats
16,553
reputation
315k
reached
399
answers
44
questions
Loading…
About

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

1
gold badge
35
silver badges
75
bronze badges
749
Score
247
Posts
56
Posts %
483
Score
157
Posts
35
Posts %
162
Score
71
Posts
16
Posts %
125
Score
46
Posts
10
Posts %
121
Score
54
Posts
12
Posts %
105
Score
48
Posts
11
Posts %
Top posts
View all questions and answers