将系列转换为字符串时未获得所需的输出

2024-05-19 10:07:46 发布

您现在位置:Python中文网/ 问答频道 /正文

使用下面的代码时,我只得到整个列的一个输出。但是我想要每一行的输出。我想知道我该怎么做?这是我从数据帧转换的字符串

from textblob.classifiers import DecisionTreeClassifier

train = [('I love this sandwich.', 'pos'),
        ('This is an amazing place!', 'pos'),
        ('I feel very good about these beers.', 'pos'),
        ('I do not like this restaurant', 'neg'),
        ('I am tired of this stuff.', 'neg'),
        ("I can't deal with this", 'neg'),
        ("My boss is horrible.", "neg")
    ]
ho=tweets['twt'] % where tweets['twt'] contains tweets in text format
a=ho.to_string(buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, sparsify=False, index_names=True, justify=None, line_width=None, max_rows=None, max_cols=None, show_dimensions=False)

cl = DecisionTreeClassifier(train)        
blob = TextBlob(a, classifier=cl)
for s in blob.sentences:
    print(s)
    print(s.classify())

当前output:- enter image description here


Tags: inposnonefalsetrueformatindexis

热门问题