0
点赞
收藏
分享

微信扫一扫

批量csv转xlsx代码

罗子僧 2022-04-14 阅读 35
python
# 模块导入
import os
from pandas import read_csv

# 输入csv文件们 所在的 文件夹
file_path = "F:/data/hhy/hhy_NDVI/hhy/Zonal/permafrost/"

# 输出的xlsx文件们 所在的 文件夹
out_path = "F:/data/hhy/hhy_NDVI/hhy/Zonal/permafrost/excel/"

# 输入文件的文件名后缀
ext_name = "csv"

# 遍历输入文件夹下的所有文件
for in_file in os.listdir(file_path):
    # 如果文件名后缀符合csv
    if in_file.endswith(ext_name):
        f_name = os.path.splitext(in_file)
        print(f_name)
        
        path = file_path + in_file
        file = open(path)
        data = read_csv(file)
        
        # 输出为xlsx
        data.to_excel(out_path + f_name[0] + ".xlsx")
        
print("finish")
举报

相关推荐

0 条评论