def main(path_to_data, column_to_deal, output_file, input_ncores):
'''
??logging??
'''
logger = logging.getLogger('mylogger')
logger.setLevel(logging.INFO)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('[%(levelname)-3s]%(asctime)s %(filename)s[line:%(lineno)d]:%(message)s')
console.setFormatter(formatter)
logger.addHandler(console)
'''
??????
'''
data = pd.read_excel(path_to_data)
logger.info("??????...")
re_sub_vec = np.vectorize(re_sub) # ?????
data[column_to_deal] = re_sub_vec(data[column_to_deal])
logger.info("??????...")
data['content_list'] = data[column_to_deal].map(sentence_split)
seg_word = jieba4null(n_core = input_ncores)
data.loc[:,'seg_words'] = data['content_list'].map(seg_word.cut_sentence)
logger.info("????????...")
pool = Pool(input_ncores)
worker = polar_classifier()
data['sentiment'] = pool.map(worker.multi_list_classify, data['seg_words'])
data = data.drop(['content_list','seg_words'], axis = 1)
logger.info("????????...")
writer = pd.ExcelWriter(output_file)
data.to_excel(writer, sheet_name='sheet1', encoding='utf-8', index=False)
writer.save()
logger.info("Task done!")
Jeffmxh_sentiment_analyse.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录