给定一个 Graphlab SFrame:
+-------+------------+---------+-----------+
| Store | Date | Sales | Customers |
+-------+------------+---------+-----------+
| 1 | 2015-07-31 | 5263.0 | 555.0 |
| 2 | 2015-07-31 | 6064.0 | 625.0 |
| 3 | 2015-07-31 | 8314.0 | 821.0 |
| 4 | 2015-07-31 | 13995.0 | 1498.0 |
| 3 | 2015-07-20 | 4822.0 | 559.0 |
| 2 | 2015-07-10 | 5651.0 | 589.0 |
| 4 | 2015-07-11 | 15344.0 | 1414.0 |
| 5 | 2015-07-23 | 8492.0 | 833.0 |
| 2 | 2015-07-19 | 8565.0 | 687.0 |
| 10 | 2015-07-09 | 7185.0 | 681.0 |
+-------+------------+---------+-----------+
[986159 rows x 4 columns]
如何通过将每行的销售额除以客户来添加“每位客户的销售额”列?
我尝试了以下方法,但它们不起作用(sf
是我的SFrame
:
sf['salespercustomer'] = sf.apply(lambda x: sf['Sales']/sf['Customers'])
有趣的是,我得到了一个 SArray 的输出:
sf['Sales'] / sf['Customers']
但这并不能真正帮助将列添加回sf
,所以这不起作用 =( :
sf['salescustomer'] = sf['Sales'] / sf['Customers']