我在构建语料库,代码如下,但最后显示语料库是空的。我在“Users/zhoushengsheng1/Documents/python_work/trumptext”路径下面,存了2个TXT的文本。
import os
import os.path
import codecs
import pandas
filePaths=[]
fileContents=[]
for root,dirs,files in os.walk(
'Users/zhoushengsheng1/Documents/python_work/trumptext'
):
for name in files:
filePath=os.path.join(root,name)
filePaths.append(filePath)
f=codecs.open(filePath,'r','utf-8')
fileContent=f.read()
f.close()
fileContents.append(fileContent)
trump=pandas.DataFrame({
'filePath':filePaths,
'fileContent':fileContents})
print(trump)
输出结果为:
Empty DataFrame
Columns: [filePath, fileContent]
Index: []
[Finished in 0.7s]
请问问题出在哪里??谢谢