写一段python代码,遍历文件夹里面所有文件,删除excel表格指定行
Jump to turn (12)
- 1写一段python代码,遍历文件夹里面所有文件,删除excel表格指定行
- 2写一段python代码,遍历文件夹里面所有文件,删除excel表格里所有工作表的第23行
- 3改进上面的代码,表格内含有中文
- 4写一段python代码,遍历文件夹里面所有文件,将excel表格里所有工作表的C23单元格的值替换为xxoo
- 5写一段python代码,遍历文件夹里面所有文件,将excel表格里所有工作表的C23单元格的值替换为xxoo,表格内包含中文
- 6运行上面代码后,出现如下错误 TypeError: init() got an unexpected keyword argument 'encoding'
- 7出现如下错误 TypeError: readexcel() got an unexpected keyword argument 'encoding'
- 8如何查看Pandas 版本
- 9debain中如何更新pandas
- 10运行上面代码,出现如下错误pandas.errors.InvalidIndexError: You can only assign a scalar value
- 11写一段python代码,遍历文件夹里面所有文件,将excel表格里所有工作表的C23单元格的值替换为xxoo,表格内包含中文
- 12怎么取消隐藏chrome的地址栏www
- User
写一段python代码,遍历文件夹里面所有文件,删除excel表格指定行
- Assistant
以下是可能的 Python 代码,可以遍历指定文件夹下的所有 Excel 表格文件,并删除指定行的数据:
pythonimport os import pandas as pd # 设置要遍历的文件夹路径 folder_path = 'C:/path/to/folder' # 要删除的行数 rows_to_delete = [3, 7, 9] # 遍历指定路径下的所有文件 for filename in os.listdir(folder_path): if not filename.endswith('.xlsx'): # 如果不是 Excel 文件,则跳过 continue file_path = os.path.join(folder_path, filename) df = pd.read_excel(file_path) # 删除指定行 for row in rows_to_delete: df.drop(df.index[row], inplace=True) # 保存修改后的文件 writer = pd.ExcelWriter(file_path) df.to_excel(writer, index=False) writer.save()