python一次性读取文件夹中的所有excel文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python一次性读取文件夹中的所有excel文件相关的知识,希望对你有一定的参考价值。

参考技术A import pandas as pd

import os

data=pd.read_excel('/Users/kelan/Downloads/2月5日/安徽.xlsx')

a=data.columns

df_empty=pd.DataFrame(columns=a)

for parents,adds,filenames in os.walk('/Users/kelan/Downloads/2月5日'):

    for filename in filenames:

        #print(os.path.join(parents,filename))

        data = pd.read_excel(os.path.join(parents,filename))

        df_empty=df_empty.append(data,ignore_index=True) 

df_empty.to_excel('/Users/kelan/Downloads/2月5日/11.xlsx')

注意中文写入,os.walk会返回3个参数,分别是路径,目录list,文件list,取第一个和最后一个,最后一个遍历。ignore_index可以忽略索引。开始先在pandas中建一个dataframe,columns中填写行标

用python读取带密码的excel文件中的数据

用python读取带密码的excel文件中的数据,程序代码如下:
 
#filename:readingxls.py
‘‘‘
此程序的作用为:用python读取带密码的excel文件中的数据。
首先通过pip安装xlrd第三方库 pip3 install xlrd
请输入excel文件路径:D:x1.xls
‘‘‘
import xlrd
path=input("请输入excel文件路径:")
workbook=xlrd.open_workbook(path)
b=len(workbook.sheets())
i=0
for i in range(b):
    sheet=workbook.sheet_by_index(i)
    for row in range(sheet.nrows):
        print()
        for col in range(sheet.ncols):
            print("%7s"%sheet.row(row)[col].value,‘ ‘,end=‘‘)
print()

以上是关于python一次性读取文件夹中的所有excel文件的主要内容,如果未能解决你的问题,请参考以下文章

记一次xlrd读取excel为none的解决

python怎么读取txt 格式excel文件

python读取较大数据文件

python读取较大数据文件

如何使用 Python 读取包含扩展字体的 Excel 文件? (openpyxl 错误:最大值为 14)

用python将两个excel文件中的所有工作表复制到一个新的excel?