I have a dataset where I would like a certain statement to only be applied to specific rows in my dataset. I would like this to only be applied to rows that contain [type] == 'aa', and apply second statement for rows that contain [type] == 'bb'
Data
location type mig1 de mig2 re
ny aa 8/1/2021 10/1/2021 1/1/2022 2/1/2022
ny aa 8/1/2021 10/1/2021 1/1/2022 2/1/2022
ca aa 8/1/2021 10/1/2021 1/1/2022 2/1/2022
tx bb 9/1/2021 11/1/2021 2/1/2022 3/1/2022
Desired
#Date 8/1/2022 is input, which yields:
location type mig1 de mig2 re
ny aa 03/1/2022 05/1/2022 8/1/2022 7/1/2022
ny aa 03/1/2022 05/1/2022 8/1/2022 7/1/2022
ca aa 03/1/2022 05/1/2022 8/1/2022 7/1/2022
tx bb 03/1/2021 11/1/2021 08/1/2022 3/1/2022
Logic - we see that the shift applies to all columns when the type == aa
when the type value == bb, a different statement is applied
Doing
#takes input value
datevalue = pd.to_datetime(input("Enter shift: "))
#shifts dates from the datevalue input - However I would like d variable to only be applied to the rows that contain [type] == 'aa'
#apply e variable to rows that contain [type] = 'bb'
d = {
'mig1': pd.DateOffset(months=5),
'de': pd.DateOffset(months=3),
're': pd.DateOffset(months=1),
}
e = {
'mig1': pd.DateOffset(months=5),
}
s = pd.Series(d).rsub(datevalue)
df.assign(**{**s, 'mig2': datevalue})
Any suggestion is appreciated