python中shape 0_Python错误:找到包含0个样本(shape =(0,262))的数组,同时至少需要1个...

所以我试图在python中构建一个自然学习处理器,我正在使用我在网上找到的一些代码,然后调整自己的东西。但现在,它只是不想工作。它一直在给我

ValueError: Found array with 0 sample(s) (shape=(0, 262)) while a minimum of 1 is required.

这是我的代码。我道歉,如果它是凌乱的我只是直接从互联网上复制它:

from collections import Counter

import pandas

from nltk.corpus import stopwords

import pandas as pd

import numpy

headlines = []

apps = pd.read_csv('DataUse.csv')

for e in apps['title_lower']:

headlines.append(e)

testdata = pd.read_csv('testdata.csv')

# Find all the unique words in the headlines.

unique_words = list(set(" ".join(headlines).split(" ")))

def make_matrix(headlines, vocab):

matrix = []

for headline in headlines:

# Count each word in the headline, and make a dictionary.

counter = Counter(headline)

# Turn the dictionary into a matrix row using the vocab.

row = [counter.get(w, 0) for w in vocab]

matrix.append(row)

df = pandas.DataFrame(matrix)

df.columns = unique_words

return df

print(make_matrix(headlines, unique_words))

import re

# Lowercase, then replace any non-letter, space, or digit character in the headlines.

new_headlines = [re.sub(r'[^\w\s\d]','',h.lower()) for h in headlines]

#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值