熊猫:改变列中的值

时间:2016-08-23 16:44:30

标签: python pandas

我有数据框

qsex, age ranges, RuCitySIze

和df

active_seconds

我需要列FOM_quota中的值相等,将值从res/values/dimens.xml(default) res/values-ldpi/dimens.xml (240x320 and nearer resolution) res/values-mdpi/dimens.xml (320x480 and nearer resolution) res/values-hdpi/dimens.xml (480x800, 540x960 and nearer resolution) res/values-xhdpi/dimens.xml (720x1280 - Samsung S3, Micromax Canvas HD, etc) res/values-xxhdpi/dimens.xml (1080x1920 - Samsung S4, HTC one, etc) res/values-large/dimens.xml (480x800) res/values-large-mdpi/dimens.xml (600x1024) res/values-sw600dp/dimens.xml (600x1024) res/values-sw720dp/dimens.xml (800x1280) res/values-xlarge-xhdpi/dimens.xml (2560x1600 - Nexus 10") res/values-large-xhdpi/dimens.xml (1200x1920 - Nexus 7"(latest)) 复制到View.setTextSize(size in px); 。 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

你可以这样做:

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