Pandas:更改列中的值

2024-09-30 01:23:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有数据帧

ID  RuCitySize  qsex    age ranges  url used_at active_seconds
 f78f67101c3aeb099212b8aa9a95dfd2   500-млн Женский 18-24   lada.ru 03.01.2016 20:18    66.25557348
 f78f67101c3aeb099212b8aa9a95dfd2   500-млн Женский 18-24   lada.ru/cars/vesta/sedan/tth.html   03.01.2016 20:18    51.5321127
 f78f67101c3aeb099212b8aa9a95dfd2   500-млн Женский 18-24   lada.ru/cars/4x4/3dv/prices.html    03.01.2016 20:20    22.08519116
 f78f67101c3aeb099212b8aa9a95dfd2   500-млн Женский 18-24   lada.ru/cars/4x4/3dv/1.7_8_mkpp/lux/017/114/card.html   03.01.2016 20:20    29.44692154
 740e2b36a4fa2d145436293522f5f5d5   500-млн Женский 18-24   penza-avto.lada.ru/ds/cars  05.01.2016 12:51    7.361730386
 740e2b36a4fa2d145436293522f5f5d5   500-млн Женский 18-24   penza-avto.lada.ru/ds/cars/granta/liftback/prices.html  05.01.2016 12:51    66.25557348

和df

qsex    age ranges  RuCitySize  FOM_quota
Женский 18-24   100-500 3.680865193
Женский 18-24   500-млн 1.764538469
Женский 18-24   Миллионники 2.295797363

如果列qsex, age ranges, RuCitySIze中的值相等,则需要将值从active_seconds乘到FOM_quota。 我该怎么做?你知道吗


Tags: agehtmlrudscarsactivepricesseconds
1条回答
网友
1楼 · 发布于 2024-09-30 01:23:41

你可以这样做:

In [33]: df1['new'] = (df1['active_seconds'] *
   ....:               pd.merge(df1, df2,
   ....:                        on=['qsex', 'age ranges', 'RuCitySize'],
   ....:                        how='left')['FOM_quota'])

In [34]: df1[['active_seconds','new']]
Out[34]:
   active_seconds         new
0       66.255573  116.910508
1       51.532113   90.930395
2       22.085191   38.970169
3       29.446922   51.960226
4        7.361730   12.990056
5       66.255573  116.910508

相关问题 更多 >

    热门问题