读取多个Excel文件并对其应用清理过程

时间:2019-03-28 22:27:58

标签: python-3.x

我在同一目录中有多个excel文件,我需要阅读它们并对其应用一些清洁过程,并在清洁后写入更改。是否有任何方法可以这样做。因为有很多文件,我会这样做每个文件中的过程相同,而且要花费时间

 # Create the list of file names: 
filenames = ['tweets7.xlsx', 'tweets6.xlsx']

# Create the list for the three DataFrames you want to create:
dataframes = []
for filename in filenames:
    dataframes.append(pd.read_excel(filename))

# Print top 5 rows of the 1st DataFrame in dataframes
print(dataframes[0].head(10))

我使用此代码,它可以与我一起工作,然后应用清理过程,例如删除标点符号,链接等。当我通过此代码保存清洁

dataframes['clean text'] = dataframes['Text'].apply(lambda x: processPost(x)) # apply used to call the method procssPost

错误出现

TypeError: list indices must be integers or slices, not str

0 个答案:

没有答案