我有一个有两列的数据框架。第一列(内容已清除)包含包含句子的行。第二列(有意义)包含关联的二进制标签。
我遇到的问题是,当我试图标记内容清理列中的文本时,空格会出现问题。以下是迄今为止我的代码:
df = pd.read_csv(pathname, encoding = "ISO-8859-1")
df = df[['content_cleaned', 'meaningful']]
df = df.sample(frac=1)
X = np.asarray(df[['content_cleaned']])
y = np.asarray(df[['meaningful']])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=21)
tokenizer = Tokenizer(num_words=100)
X_train = tokenizer.sequences_to_matrix(X_train.astype(np.int32), mode="binary")
X_test = tokenizer.sequences_to_matrix(X_test.astype(np.int32), mode="binary")
encoder = LabelBinarizer()
encoder.fit(y_train)
y_train = encoder.transform(y_train)
y_test = encoder.transform(y_test)
错误突出显示的代码行是:
X_train = tokenizer.sequences_to_matrix(X_train.astype(np.int32), mode="binary")
错误消息为:
invalid literal for int() with base 10: "STX's better than reported quarter is likely to bode well for WDC results."
“base 10:”后面的句子是包含文本的列中某一行的示例。这将是一个例子,我正试图标记化的句子。
我相信这是numpy的一个问题,但我也相信这可能是我标记此文本数组的方法中的一个错误。
任何帮助都会很好!