返回空系列(Series([],名称:category,dtype:object)

时间:2018-12-07 01:04:46

标签: python dataframe scikit-learn keras series

运行代码时,它适用于train_tags和打印 0培训数据 1个测试数据 名称:类别,dtype:对象

但是当我为test_tags运行相同的代码时,它给了我 系列([],名称:类别,dtype:对象)

完整代码如下:


path_train = r'C:\Users\Sgt.pookey01\Documents\Clickbait project\Article Titles'
files_train = skds.load_files(path_train,load_content=False)

files_train

{'文件名':数组(['C:\ Users \ Sgt.pookey01 \ Documents \ Clickbait项目\ Article Titles \ TrainingData \ TrainingData.txt', 'C:\ Users \ Sgt.pookey01 \ Documents \ Clickbait项目\ Article Titles \ TestingData \ TestingData.txt'], dtype ='


label_index = files_train.target
label_names = files_train.target_names
labelled_files = files_train.filenames

data_tags = ["filename","category","Article Titles"]

data_list = []
i=0
for f in labelled_files:
    data_list.append((f,label_names[label_index[i]],Path(f).read_text(encoding="utf-8")))
    i += 1

 data = pd.DataFrame.from_records(data_list, columns=data_tags)

train_size = int(len(data['Article Titles'][0])*.8)
train_posts = data['Article Titles'][:train_size]
train_tags = data['category'][:train_size]
train_files_names = data['filename'][:train_size]

train_tags

0培训数据 1个测试数据 名称:类别,dtype:对象

test_posts = data['Article Titles'][train_size:]
test_tags = data['category'][train_size:]
test_files_names = data['filename'][train_size:]

test_tags

Series([],名称:category,dtype:object)

0 个答案:

没有答案