我正在使用 Google Cloud NL API 来分析一些描述的情绪。对于某些行,错误InvalidArgument: 400 The language vi is not supported for document_sentiment analysis.不断弹出,我想围绕它建立一种方法,而不是拼命地试图找到发生这种情况的原因并删除负责任的行。不幸的是,我对 Python 比较陌生,不知道如何正确地做到这一点。
我的代码如下:
description_list = []
sentimentscore_list=[]
magnitude_list=[]
# Create a Language client
language_client = google.cloud.language.LanguageServiceClient()
for i in range(len(description)): # use the translated description if the original description is not in English
if description_trans[i] == '':
descr = description[i]
else:
descr = description_trans[i]
document = google.cloud.language.types.Document(
content=descr,
type=google.cloud.language.enums.Document.Type.PLAIN_TEXT)
# Use Language to detect the sentiment of the text.
response = language_client.analyze_sentiment(document=document) …Run Code Online (Sandbox Code Playgroud) 我想知道如何同时获取超过 1 列。这是我到目前为止的代码,但我收到错误:
ValueError: too many values to unpack (expected 2)
con = sqlite3.connect('database.db')
cur = con.cursor()
cur.execute("SELECT name, age FROM employees")
name, age = cur.fetchall()
Run Code Online (Sandbox Code Playgroud)
实际上是否可以同时获取超过 1 列?谢谢!