ValueError: Specified \n as separator or delimiter. This forces the python engine which does not accept a line terminator. Hence it is not allowed to use the line terminator as separator.但是刚才那段代码发生了如上报错,怎么办,请修改
时间: 2024-02-19 20:59:13 浏览: 501
ValueError: Could not find a format to read the specified file in mode ‘i’
可以尝试将 `engine='python'` 修改为 `engine='c'`,这样就可以避免这个错误。修改后的代码如下:
```
import pandas as pd
import numpy as np
word = pd.read_csv("D:/SHUJUWAJUE/data/word.csv")
pos_comment = pd.read_csv("D:/SHUJUWAJUE/第六节用/data/正面评价词语(中文).txt", header=None, sep="\n", encoding='utf-8', engine='c')
neg_comment = pd.read_csv("D:/SHUJUWAJUE/第六节用/data/负面评价词语(中文).txt", header=None, sep="\n", encoding='utf-8', engine='c')
pos_emotion = pd.read_csv("D:/SHUJUWAJUE/第六节用/data/正面情感词语(中文).txt", header=None, sep="\n", encoding='utf-8', engine='c')
neg_emotion = pd.read_csv("D:/SHUJUWAJUE/第六节用/data/负面情感词语(中文).txt", header=None, sep="\n", encoding='utf-8', engine='c')
positive = set(pos_comment.iloc[:,0]) | set(pos_emotion.iloc[:,0])
negative = set(neg_comment.iloc[:,0]) | set(neg_emotion.iloc[:,0])
intersection = positive & negative
positive = list(positive - intersection)
negative = list(negative - intersection)
positive = pd.DataFrame({"word":positive, "weight":[1]*len(positive)})
negative = pd.DataFrame({"word":negative, "weight":[-1]*len(negative)})
posneg = positive.append(negative)
```
希望这次修改能够解决你的问题。
阅读全文