I would like to add to my DF 4 new columns with boolean type representing quarters of the year. I have column with month numbers and would like to get this result:
month Q1 Q2 Q3 Q4
6 0 1 0 0
7 0 0 1 0
8 0 0 1 0
9 0 0 1 0
10 0 0 0 1
11 0 0 0 1
12 0 0 0 1
1 1 0 0 0
At the moment I have tried this code:
print("Quarters")
quarters = {'Q1': [1, 2, 3], 'Q2': [4, 5, 6], 'Q3': [7, 8, 9], 'Q4': [10, 11, 12]}
for quarter, value in quarters.items():
df_analysis[quarter] = (df_analysis["month"].isin(value))*1
Which works however I get following error: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame I have tried also:
df_analysis.loc[:, quarter] = (df_analysis.loc[:, "month"].isin(value))*1
However warning is still showing up. Could you please help how to write it correctly?