Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将所有.xls转换为.xlsx_Python_Pandas - Fatal编程技术网

Python 将所有.xls转换为.xlsx

Python 将所有.xls转换为.xlsx,python,pandas,Python,Pandas,您好,我在将所有.xls文件转换为.xlsx时遇到问题。另一个挑战是每个.xls文件都有多个工作表,我有很多文件要转换。你能找个人帮我解决吗 import glob import pandas as pd import os from pandas import ExcelWriter _list_of_xls_files = glob.glob(r'C:\Users\enter_your_pc_username_here\Documents\*xls') for _xls_file in

您好,我在将所有.xls文件转换为.xlsx时遇到问题。另一个挑战是每个.xls文件都有多个工作表,我有很多文件要转换。你能找个人帮我解决吗

import glob
import pandas as pd
import os
from pandas import ExcelWriter

_list_of_xls_files = glob.glob(r'C:\Users\enter_your_pc_username_here\Documents\*xls')

for _xls_file in _list_of_xls_files:
    df = pd.read_excel(_xls_file,sheet_name = None)
    _list_of_tabs_inside_xls_file = df.keys()

    with ExcelWriter(str(_xls_file).replace('.xls','.xlsx')) as writer:

        for n, _sheet_name in enumerate(list_of_tabs_inside_xls_file):

            df[_sheet_name].to_excel(writer,'sheet%s' % n)
资料来源:

一,