给定一个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]
graphlab/other python函数中是否有一种简单的方法将日期列转换为Year | Month | Day?
^{pr2}$在pandas
中,我可以这样做:Which is the fastest way to extract day, month and year from a given date?
但要将SFrame转换为Panda来分割日期并转换回SFrame是一件相当麻烦的事。在
一个快速而肮脏的方法是
另一个选择是将
Date
列转换为datetime类型,然后使用graphlab.SArray.split_datetime
函数。在也可以使用split datetime方法来完成。它给你更多的灵活性。在
split_datetime
方法本身位于SArray
(SFrame的一个列)上,它返回一个SFrame,然后您可以将它添加回原始数据(基本上成本为0)相关问题 更多 >
编程相关推荐