python - 在 Python 中计算数据框中的单词
问题描述
我已经使用 pandas 将 CSV 文件导入 Python。该文件由 3 列和 498 行组成。我只需要一个名为“描述”的列的字数。我已经通过将“描述”列转换为小写,删除英文停用词和拆分来清理文件。
输入:
import pandas as pd
df = pd.read_csv("capex_motscles.csv")
from nltk.corpus import stopwords
stop = stopwords.words('english')
Description3 = df['Description'].str.lower().apply(lambda x:
''.join([word for word in str(x).split() if word not in (stop)]))
print(Description3)
输出:
0 crazy mind california medical service data base...
1 california licensed producer recreational & medic...
2 silicon valley data clients live beyond status...
3 mycrazynotes inc. announces $144.6 million expans...
4 leading provider sustainable energy company prod ...
5 livefreecompany founded 2005, listed new york stock...
我从“print(Description3)”中提供了 5 行。我总共有 498 行,如前所述,我需要计算词频。任何帮助将不胜感激,感谢您的宝贵时间!
解决方案
你的意思是这样的吗?
df['Description3'] = df['Description'].str.lower().apply(lambda x:
''.join([word for word in str(x).split() if word not in (stop)]))
df['Description3'].str.split(expand=True).stack().value_counts()
推荐阅读
- mysql - CTE 正在返回一个空集
- javascript - JS 正则表达式在文本中查找 json 字符串
- python - 当我尝试解析具有重复元素的字典结构时,出现错误“CMessage' 对象不适用于 'str' 对象”
- javascript - 使用 Leaflet 显示离线 ArcGIS Esri 地图
- c# - 无法从 Microsoft Azure 下载机器人源代码
- azure-cosmosdb - StatusCode = 429 时的 Cosmos db 费用是多少
- python-3.x - 在 intermapper 中组合探针文件
- javascript - 使用重载 TypeScript 方法的可选参数
- javascript - 通过 Angular 在 json 对象中显示列表的最佳方式
- c - 通过 scanf 检查输入是否正确