python_使用需要的气象台站提取气象数据

# -*- coding: utf-8 -*-
"""
Created on Fri Oct 20 15:55:54 2017
使用气象台站提取数据 
@author: Administrator
"""
import pandas as pd
import os  
site=['58027','58040','58102','58221','58238','58251','58314','58321','58362','58424','58457','58633','58477','58752']

path3=r'C:\Users\Administrator\Desktop\climatedata\1961-1976\TEM1'#输入路径
path4=r'C:\Users\Administrator\Desktop\climatedata\1961-1976\TEM_Extract' #输出路径
filespath= os.listdir(path3) 
for y in filespath:
    print(y)
    x=y.split('.') #分离文件名
    diropen=path3+'\\'+y #提取前文件完整路径
    diropen1=path4+'\\'+x[0]+'.csv'#提取后文件完整路径
    newf=pd.read_table(diropen,header=None,encoding='gbk',delim_whitespace=True,index_col=0)#使用dataframe读取TXT
    writef=open(diropen1,'w+')
    for number in site:
        f3=[]
        if number in newf.index:
            print(number)
            print(newf.ix[number])
            f3.append(newf.ix[number])#设置文件内容索引
            
            newf.ix[number].to_csv(writef,header=False)#写入到新的CSV,这里CSV与之前的TXT文件名相同

 

 

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值