A sample dataframe as mentioned below:
df_A = pd.DataFrame({'field1':[1,2,3,4,5], 'field2':[11,12,13,14,15], 'field3':[c1,c2,c3,c4,c5], 'field4':[m1,m2,m3,m4,m5], 'field5':[21,22,23,24,25], 'field6':[f1,f2,f3,f4,f5], 'field7':[31,32,33,34,35]})
I have a logic as mentioned below:
df_A['field7'] = df_A[(df_A['filed4']== 'abc') & (df_A['field5']== 'def')].groupby(['field1', 'field2','field3'], as_index=False)[['field6']].transform('count')
but in some scenarios the filter might yield no values and I am getting the following error:
ValueError: No objects to concatenate
Though I partially understand what the error is, I am not able to get the null value column as my expected answer(Example to apply groupby on an empty dataframe: Keep columns after a groupby in an empty dataframe)
Kindly let me know if I was wrong in any sense and Thanks in advance!
Edit: Added an example dataframe for the above mentioned case