最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Assign unique codes for different User Id based on conditions - Stack Overflow

programmeradmin2浏览0评论

I have to assign a unique code from vouchers to every user id, with the condition of trips have to be the same. For example, if a user made 3 trips, it will be assigned a voucher of trips == 3. The column used is binary.

  1. winners: columns user id, trips
  2. vouchers: columns code, used, trips

I tried this:

vouchers_disponibles = vouchers[vouchers["used"].isna()].copy()

test = ganadores.head(1000) 
df_test = test.merge(vouchers_disponibles, left_on='DO sin dcto', right_on='viajes', how='left') df_test.drop_duplicates(subset=['User Id'])

But this will duplicate values from the user id for every code

发布评论

评论列表(0)

  1. 暂无评论