使用PySpark进行数据框计算

时间:2019-11-23 08:03:01

标签: pyspark pyspark-sql pyspark-dataframes

我有两个数据框。 df1-

product        sale       total_sale          Ppenitration%
  a             100        600                     17
  b             200        600                     33
  c             300        600                     50

df2-

area          product          sale         total_sale      Ppenitration%       
abb             a               10            60                  17
abb             b               25            60                  42
abb             c               25            60                  42
mno             a               25            100                 25
mno             b               30            100                 30
mno             c               45            100                 45
rr              a               30            180                 17
rr              b               80            180                 44
rr              c               70            180                 39

我希望数据框看起来像-

area          product          sale         total_sale      Ppenitration%           index%       rank
abb             a               10            60                  17                   0            2
abb             b               25            60                  42                   25           1
abb             c               25            60                  42                  -17           3
mno             a               25            100                 25                   50           1
mno             b               30            100                 30                  -10           2
mno             c               45            100                 45                  -10           3
rr              a               30            180                 17                    0           2
rr              b               80            180                 44                   33           1
rr              c               70            180                 39                   -22          3

index%计算= df2.Ppenitration%/ df1.product.Ppenitration%-1(基于Excel),排名基于index%。 如何在pyspark中做到这一点?

0 个答案:

没有答案