【问题标题】:graphlab create sframe combine two columngraphlab 创建 sframe 合并两列
【发布时间】:2016-08-23 11:35:07
【问题描述】:

我有两列带有字符串。假设 col1 和 col2 现在我们如何将 col1 和 col2 的内容与 graphlab SFrame 结合到 col3 中?

col1 col2
23    33
42    11
........

进入

col3
23,33
42,11
....

unstack 只会给 sarray 或 dict,我只有一个一袋字

试过了

user_info['X5']=user_info['X3'].apply(lambda x:x+','+user_info['X4'].apply(lambda y:y))

好像不对

有什么想法吗?

【问题讨论】:

    标签: python pandas graphlab


    【解决方案1】:

    使用熊猫:

    In [271]: df
    Out[271]: 
       col1  col2
    0    23    33
    1    42    11
    
    In [272]: df['col3'] = (df['col1'].map(str) + ',' + df['col2'].map(str))
    
    In [273]: df
    Out[273]: 
       col1  col2   col3
    0    23    33  23,33
    1    42    11  42,11
    

    使用graphlab:

    In [17]: sf
    Out[17]: 
    Columns:
        col1    int
        col2    int
    
    Rows: 2
    
    Data:
    +------+------+
    | col1 | col2 |
    +------+------+
    |  23  |  33  |
    |  42  |  11  |
    +------+------+
    [2 rows x 2 columns]
    
    In [18]: sf['col3'] = sf['col1'].apply(str) + ',' + sf['col2'].apply(str)
    
    In [19]: sf
    Out[19]: 
    Columns:
        col1    int
        col2    int
        col3    str
    
    Rows: 2
    
    Data:
    +------+------+-------+
    | col1 | col2 |  col3 |
    +------+------+-------+
    |  23  |  33  | 23,33 |
    |  42  |  11  | 42,11 |
    +------+------+-------+
    [2 rows x 3 columns]
    

    【讨论】:

    • 是的,但是我们如何在 graphlab create 中做到这一点?
    • 我明白了,经过测试的工作。为什么申请(str)?可以申请(int)吗?
    • @ikel ','string。您不能将 stringint 类型的对象连接起来。
    猜你喜欢
    • 2017-04-11
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 2016-02-20
    相关资源
    最近更新 更多