基于Python将csv数据转换为EXCEL数据

        将用“,”和Tab键分隔的csv数据转换为excel数据(分好列的)

from osgeo import gdal, ogr
import glob
import  os
from tqdm import tqdm
import pandas as pd
from pathlib import Path

# # ds = gdal.Warp(tif_out, tif_input, format='GTiff', cutlineDSName=shp_boundary, cropToCutline=True, dstNodata=0)
# gdal.Warp(clipped_path,raster_path, format = 'GTiff',cutlineDSName = vector_path,cropToCutline=True)
#输入路径
src_root = r'F:\Solar_Radiance\BSRN_SSR\Station_data\*.TXT'
dst_root = r'F:\Solar_Radiance\BSRN_SSR\Station_data\EXCEL'
src_list = glob.glob(src_root)
# print(len(src_list))
# print(src_list,'src_list')

for src_dir in tqdm(src_list):
    dst_dir = os.path.join(dst_root,Path(src_dir).stem + '.xlsx')

    # read the text file
    df = pd.read_csv(src_dir, delimiter='\t|,', engine='python')

    # write the data to an Excel file
    df.to_excel(dst_dir, index=False)

    

你可能感兴趣的:(python)