I have a dataframe, df, where I would like to create a map for multiple columns in Python.
Data
id date type
aa q1 2021 aa
bb q1 2022 aa
cc q1 2021 aa
cc q1 2022 aa
cc q1 2023 bb
Desired
id date type source
aa q1 2021 aa 10
bb q1 2022 aa 20
cc q1 2021 aa 10
cc q1 2022 aa 20
cc q1 2023 bb 50
Logic
when we come across the year 2021 and the type aa, the source value will be 10 when we come across the year 2022 and the type aa, the source value will be 20 when we come across the year 2023 and the type bb, the source value will be 50
Doing
map = pd.DataFrame([
{'id': 'aa', 'date': '2021', 'source': 10},
{'id': 'bb', 'date': '2022', 'source': 20}
])
df['source'] = df1.type.replace(map,regex=True)