# -*- 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文件名相同