从vs cod中的csv文件导入

2024-06-01 14:17:17 发布

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

我想把我的代码从read和process从一个句子字符串改为从csv文件读取,然后逐行处理。在

这是我用VS代码编写的程序。在

import paralleldots
paralleldots.set_api_key("API KEY")


# for single sentence
text="Come on, lets play together"
lang_code="en"
response=paralleldots.sentiment(text,lang_code)
print(response)

我希望输出是针对特定csv文件中的每一行句子运行的,而不是仅仅从一个句子字符串中。在


Tags: 文件csv字符串代码textimport程序lang
1条回答
网友
1楼 · 发布于 2024-06-01 14:17:17
fp = open('C:/Users/User/Desktop/hj.txt',encoding='utf-8' ,errors='ignore' ) # Open file on read mode
lines = fp.read().split("\n") # Create a list containing all lines
fp.close() # Close file
print(lines)
#print("                       ...   \n") 

print("\nThe emotion analysis results for each sentence in the file .txt :") 
print("                        ...   \n") 
response=paralleldots.batch_emotion(lines)
print(response)

这很有效。在

相关问题 更多 >