Python删除指定列
发布时间
阅读量:
阅读量
import os
import pandas as pd
# 定义文件夹路径
folder_path = r'D:\R\month\xinjiang'
# 获取文件夹中所有.xlsx文件
xlsx_files = [f for f in os.listdir(folder_path) if f.endswith('.xlsx')]
# 遍历每个.xlsx文件
for file in xlsx_files:
# 读取.xlsx文件
file_path = os.path.join(folder_path, file)
df = pd.read_excel(file_path)
# 删除"PRCP"列
df.drop(columns=['PRCP'], inplace=True)
# 保存修改后的文件
df.to_excel(file_path, index=False)
【当然,接下来将逐一分析这段代码中各个函
全部评论 (0)
还没有任何评论哟~
