我正在尝试制作一个使用这些函数的程序get_neg
并get_pos
收集有关调用文件的信息project_twitter_data.csv
并创建一个包含有关有多少负面和正面单词的信息的 csv。正如您在第 4-7 行看到的(我将复制/粘贴我当前的所有代码),我只是在测试尝试制作一个没有任何花哨的东西的 csv,但由于某种原因出现错误:
**
NotImplementedError:第 1 行的 Skulpt 中尚未实现 csv
**
然后我在谷歌上搜索“什么是 Skulpt”并找到了一个脂肪百分比测量器网站。有人可以向 Python noob 解释错误的含义以及如何解决它吗?
(PS这里是代码):
#
import csv
with open('resulting_data.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerow(['first line', '2nd line'])
punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
# lists of words to use
positive_words = []
with open("positive_words.txt") as pos_f:
for lin in pos_f:
if lin[0] != ';' and lin[0] != '\n':
positive_words.append(lin.strip())
negative_words = []
with open("negative_words.txt") as pos_f:
for lin in pos_f:
if lin[0] != ';' and lin[0] != '\n':
negative_words.append(lin.strip())
twitter = []
with open("project_twitter_data.csv") as pos_f:
for lin in pos_f:
if lin[0] != ';' and lin[0] != '\n':
twitter.append(lin.strip())
print(twitter)
#######################
def strip_punctuation(x):
lst = []
for letter in x:
if not letter in punctuation_chars:
lst.append(letter)
return ("".join(lst))
######################
def get_neg(x):
lst = []
original_lst_name = []
var = 0
string = x.lower()
original_lst_name = string.split(" ")
print(original_lst_name)
for letter in original_lst_name:
if strip_punctuation(letter) in negative_words:
var += 1
print(var)
print(letter)
return (var)
#######################
def get_pos(x):
lst = []
original_lst_name = []
var = 0
string = x.lower()
original_lst_name = string.split(" ")
print(original_lst_name)
for letter in original_lst_name:
if strip_punctuation(letter) in positive_words:
var += 1
print(var)
print(letter)
return (var)
#########################