gpt4 book ai didi

python - 如何在 Graphlab SFrame 中通过划分两列来创建新列?

转载 作者:行者123 更新时间:2023-12-01 04:20:26 25 4
gpt4 key购买 nike

给定一个 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']

最佳答案

最后一行代码应该可以解决问题,但你说你的 SFrame 名为 sf,而不是 train。当我用 sf 尝试它时,它工作得很好。

关于python - 如何在 Graphlab SFrame 中通过划分两列来创建新列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33792798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com