I just learn to use python do emotional analysis, follow a teacher to learn on mechanical compression code and code without error, but also failed to remove repetition of words, make the along while also didn't understand, ask master to help have a look, I put the code in both before and after the data came from a CVS import goods comments column
This code might look for eye, can go to my blog https://blog.csdn.net/adamsww/article/details/106384090
//
Data=https://bbs.csdn.net/topics/pd.DataFrame (data) [r]. 'content' unique ())
Def cutword (STRS, reverse=False) :
S1=[] # save a character
S2=[] # save a second character
S=[] # to save the final result
If the reverse:
STRS=STRS] [: : - 1
S1. Append (STRS [0])
For I in STRS [1] :
If I==s1 [0] :
If len (s2)==0:
S2. Append (I)
The else:
If s1==s2:
S2=[]
S2. Append (I)
The else:
S=s + s1 + s2
S1=[]
S2=[]
S1. Append (I)
The else:
If s1==s2 and len (s1) & gt;=2 and len (s2) & gt;=2:
S=s + s1
S1=[]
S2=[]
S1. Append (I)
The else:
If len (s2)==0:
S1. Append (I)
The else:
S2. Append (I)
If s1==s2:
S=s + s1
The else:
S=s + s1 + s2
If the reverse:
Return '. Join (s] [: : - 1)
The else:
Return '. Join (s)
# mechanical compression to word
# use aplly from using a for loop
Manual, data2=data. Iloc [0]. Apply (cutword)
Data2=data2. Apply (cutword, reverse=True)
Print (' mechanical compression to go after the words: ')
Print (len (data2))
Print (type (data2))
Print (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ')
Var foo='bar';