This should solve your problem :)
Please add your code attempty and at least an example dataframe definition to your next question, so we do not have to invent examples to help you. An exact example of what the final result should look like would also have been great :)
Edit I adjusted the code to your changed question.
import pandas as pd
df = pd.DataFrame(
{"col_opptype": ["a", "b", "c", "d"],
"col_first": [1,0,1,0] }
)
def is_first_opptype(opptype: str, wanted_type:str, first: int):
if first and opptype == wanted_type:
return opptype + "_first"
elif not first and opptype == wanted_type:
return opptype + "_notfirst"
else:
return opptype
df["col_opptype"] = df.apply(lambda x: is_first_opptype(x["col_opptype"],
x["col_first"], "a"), axis=1)
print(df)
output:
col_opptype col_first
0 a_first 1
1 b 0
2 c 1
3 d 0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…