gpt4 book ai didi

python - graphlab 创建 sframe 合并两列

转载 作者:太空宇宙 更新时间:2023-11-04 00:46:59 25 4
gpt4 key购买 nike

我有两列字符串。让我们说 col1 和 col2现在我们如何使用 graphlab SFrame 将 col1 和 col2 的内容合并到 col3 中?

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

进入

col3
23,33
42,11
....

unstack只会给sarray或者dict,我只有一个bag of words

尝试过

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/

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