I have a dataframe, df, where I have two columns that contain certain values. If the values match a specific string, I would like to then place a certain value in a new column for multiple columns.
Data
ID Quarter Delivery
A Q1 2022 Q3 2022
A Q1 2022 Q3 2022
B Q1 2022 Q3 2022
B Q1 2022 Q3 2022
Desired
ID Quarter Delivery QuarterFull DeliveryFull
A Q1 2022 Q3 2022 1/1/2022 07/1/2022
A Q1 2022 Q3 2022 1/1/2022 07/1/2022
B Q4 2022 Q2 2023 10/1/2022 04/1/2023
B Q4 2022 Q2 2023 10/1/2022 04/1/2023
Q1 = 01
Q2 = 04
Q3 = 07
Q4 = 10
Doing
for Quarter, item in df.iteritems():
if df['Quarter'] == df['Q1 2022']:
return df['1/1/2022']
elif df['Quarter'] == df['Q4 2022']:
return df['10/1/2022']
elif df['Delivery'] == df['Q3 2022']:
return df['07/01/2022']
elif df['Delivery'] == df['Q2 2023']:
return df['04/01/2023]
else:
return df['None']
I believe running a loop may be the best way to approach since I have a decent sized dataset of 100,000 rows. I am not sure how to add these two new columns to the dataframe while using the loop. Any suggestion is appreciated