python - graphlab创建sframe合并两列

标签 python pandas graphlab

我有两列带有字符串。假设 col1 和 col2 现在我们如何使用 graphlab SFrame 将 col1 和 col2 的内容合并到 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))

好像不对

有什么想法吗?

最佳答案

使用 Pandas :

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

使用图实验室:

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]

关于python - graphlab创建sframe合并两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39091454/

相关文章:

python - 不正确的 : usage of hyperopt with tensorflow

python - 在python中高效读取和验证csv文件

python - 更改Python中Hexbin图中的x和y输入范围

pycharm - graphlab.SFrame.show()错误: Requested port is unavailable: None

python - : ImportError: "No module named ' graphlab'?如何解决

Python,从 FFMPEG 中获取帧号

python - 在python中以动态方式创建嵌套循环

python - 具有单个条件的多行 If 语句

python - 在数据帧上乘以向量 - 向量化

python绘图通过groupby过滤