I have this dataframe, I need to create a reached_det and reached_web column in Pandas dataframe. The conditions for this is if sum of detail for any particular geo_id > 0, then reached_det for that id is 1. Similarly for reached web.
The Final data will look like this
Condition is shown below
My code in python. It is giving me error. Please help
data['reached_det'] =np.where(data.groupby('geo_id'])['det'].sum()>0,1,0)
Try change it with transform
data['reached_det'] = np.where(data.groupby('geo_id'])['det'].transform('sum')>0, 1, 0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.