-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDataProcess.py
More file actions
25 lines (22 loc) · 882 Bytes
/
Copy pathDataProcess.py
File metadata and controls
25 lines (22 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy as np
import pandas as pd
import re
import jieba
import matplotlib.pyplot as plt
stop_words = pd.read_csv('百度停用词列表.txt',encoding='gb18030',header=None).values
def text_process(text):
text = text.lower()
clear_list = '[,,。,.,?,!,【,】,(,),(,),、,%,@,/,$,-,:,:,《,》,<,>,…,#,?,·,♀,=,!,"w",~]'
text = re.sub(clear_list, "", text)
text = re.sub(r"\[.*?\]", "", text)
text = re.sub(r"\d+", "", text)
text = text.strip()
jieba.load_userdict("词典.txt")
text = list(jieba.lcut(text))
text = [word.strip() for word in text if word not in stop_words]
return text
if __name__ == '__main__':
danmaku = pd.read_csv('84887919comments1650424641.8339486.csv', encoding='gb18030').iloc[:, 5]
danmaku = danmaku.apply(text_process)
for i in danmaku:
print(i)