哪位大神帮我看一下我写的python代码,运行时没有显示错误,但没有执行。
#-*-coding:utf-8-*-importcodecsimportosimportshutilimportjiebaimportjieba.analyseimpo...
#-*-coding:utf-8-*-import codecs import os import shutil import jieba import jieba.analyse import sysimport jieba.posseg as psegimport reimport numpy as npimport pandas as pdimport xlrdimport xlwtfrom string import punctuationdef main(): filepath="C:\\Users\\Administrator\\Desktop\\小学1-6年级每个年级文章词频占比分析\\一年级课文单篇\\待分词" reapath="C:\\Users\\Administrator\\Desktop\\小学1-6年级每个年级文章词频占比分析\\一年级课文单篇\\分词后\\" apathDir=os.listdir(filepath) for allDir in apathDir: info = os.path.join(filepath,allDir) #child = os.path.join('%s%s' % (filepath, allDir)) #print child.decode('utf-8') #fileName=filepath+str(allDir)+".txt" file = codecs.open('info', 'r',encoding='utf-8') add_punc=',。、【 】 “”:;()《》‘’{}?!⑦()、%^>℃:.”“^-——=@¥1234567890' all_punc=punctuation+add_punc content = file.read() file.close() #segments = [] ##对内存中的字符串进行分词 listzk1 = list(jieba.cut(content)) te2=[] for i in listzk1: te2.append(i) if i in all_punc: te2.remove(i) listzk = [] the_set = set() for level in te2: listzk.append(level) df = pd.DataFrame(listzk,columns=['word']) count=1 reafileName=reapath+count+".csv" df.to_csv('reafileName', sep=',',header=False,index=False) count+=1
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询