循环读文件并相加

2019-04-22  本文已影响0人  Aerosols

画图的时候,注意把云和缺测去掉,设最大值。最后记得把nan设为-999.

import os
import pandas as pd
import numpy as np
import glob

hgt=np.arange(30,6030,30)

path=r'E:\2017年消光和偏振'
file=glob.glob(os.path.join(path, "sphere*.txt"))

db=[]
for f in file:
 db.append(pd.read_csv(f,sep='\s+',header=None,index_col=0,nrows=96))
sp=pd.concat(db)
sp.columns=hgt;

path=r'E:\2017消光和偏振'
file1=glob.glob(os.path.join(path, "dust*.txt"))

db1=[]
for f in file1:
 db1.append(pd.read_csv(f,sep='\s+',header=None,index_col=0,nrows=96))
dust=pd.concat(db1)
dust.columns=hgt

sp.replace([-999000,-9999000],np.nan,inplace=True)
sp[sp<0]=0

dust.replace([-999000,-9999000],np.nan,inplace=True)
dust[dust<0]=0

sp=sp.sort_index(level=0)
dust=dust.sort_index(level=0)

result=sp+dust
result.replace(np.nan,-999,inplace=True)
result=result.sort_index(level=0)
result.to_csv(r'E:\lidar2017_SP_Dust_.csv', index=True, sep=',')

上一篇下一篇

猜你喜欢

热点阅读