我是python的新手,我正在尝试按以下方式进行枚举。但是,我收到了错误
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我的csv文件只是一列,列标题为“标题”,我希望textblob处理此列数据。请帮助我。
代码:
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
from textblob import TextBlob
import datetime
from datetime import time
import warnings
import csv
df = pd.read_csv(r'C:\Test.csv')
for idx, Headlines in enumerate(df['Headlines'].values): #for each row in our df dataframe
newsText = df['Headlines']
if Headlines:
soup = BeautifulSoup(newsText,"lxml")
sentA = TextBlob(soup.get_text())
我的数据框示例:
Headlines <br/>
-- ECONOMICS BRIEF: S&P Global Earlier Expected Fed to Raise Rates Two Times in 2017, with First One Coming in June; Follows This Week's FOMC Minutes<br/>
$50, note of choice for criminals: RBA<br/>
$A falls after RBA rates decision<br/>
$A falls on RBA's house market warning<br/>
$A falls on RBA's house market warning<br/>
$A higher after Fed minutes<br/>
回溯:
Traceback (most recent call last):
File "<input>", line 20, in <module>
File "C:\PycharmProjects\____\venv\lib\site-packages\bs4\__init__.py", line 225, in __init__
markup, from_encoding, exclude_encodings=exclude_encodings)):
File "C:\PycharmProjects\____\venv\lib\site-packages\bs4\builder\_lxml.py", line 117, in prepare_markup
markup, try_encodings, is_html, exclude_encodings)
File "C:\PycharmProjects\_____\venv\lib\site-packages\bs4\dammit.py", line 228, in __init__
self.markup, self.sniffed_encoding = self.strip_byte_order_mark(markup)
File "C:\PycharmProjects\____\venv\lib\site-packages\bs4\dammit.py", line 280, in strip_byte_order_mark
if (len(data) >= 4) and (data[:2] == b'\xfe\xff') \
File "C:\PycharmProjects\_____\venv\lib\site-packages\pandas\core\generic.py", line 1573, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().