You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用word2number库时出现AttributeError:无word_to_num属性的问题

解决word2number库AttributeError问题

问题根源是导入方式错误:word_to_num方法不属于word2number顶层模块,而是存在于其内部的w2n子模块中,直接导入顶层模块自然找不到该属性。

修正后的代码

!pip install word2number
import pandas as pd
import math
from sklearn import linear_model
from word2number import w2n  # 正确导入子模块

print("successfully imported all the libraries")

df = pd.read_csv('hiring.csv')
print(df)

print(w2n.word_to_num('one'))  # 可正常执行

也可以用别名方式导入子模块:

import word2number.w2n as w2n

两种导入方式都能让你正常调用word_to_num方法,将文字数字转换为数值类型,满足多元模型的数据处理需求。

内容的提问来源于stack exchange,提问作者tanush_sunil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 21:15:05