python - 如何将数据与 CountVectorizer 功能合并
问题描述
这是我的数据集
body customer_id name
14828 Thank you to apply to us. 5458 Sender A
23117 Congratulation your application is accepted. 5136 Sender B
23125 Your OTP will expire in 10 minutes. 5136 Sender A
这是我的代码
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
b = a['body']
vect = CountVectorizer()
vect.fit(b)
X_vect=vect.transform(b)
pd.DataFrame(X_vect.toarray(), columns=vect.get_feature_names())
输出是
10 application apply ... your
0 0 0 1 0
1 0 1 0 1
2 1 0 0 1
我需要的是
body customer_id name 10 application apply ... your
14828 Thank you to apply to us. 5458 Sender A 0 0 1 0
23117 Congratulation your application is accepted. 5136 Sender B 0 1 0 1
23125 Your OTP will expire in 10 minutes. 5136 Sender A 1 0 0 1
假设我如何做到这一点?我仍然希望使用CountVectorizer
,以便将来可以修改该功能
解决方案
推荐阅读
- python - 找到像素区域质心的更快方法
- scala - 您可以将字节数组转换为字符串数组,然后再转换回字节数组吗?
- java - 如何转换日期”格式,包括 IST
- database - 为什么将主键与其他(非空)列组合在 PostgreSQL 中不会自动唯一?
- c++ - 代码完成在 C++2a 的 Clion 2019.1 中不起作用
- laravel - 使用没有 jquery 的引导模式提交表单并在日历中显示事件
- sql - ORA-00917: PLSQL 中缺少逗号
- drop-down-menu - Flutter - 如何从 DropdownButton 对齐所选项目?
- java - 如何使用 apigateway 保护基于 Java 的 REST API
- google-cloud-platform - 匿名调用者没有 storage.objects.create 访问权限,但我的 JWT 有范围 https://www.googleapis.com/auth/devstorage.full_control