Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

How to combine data arrays by multi longitude and latitude in one dataset in python

I made for loop of my data array of each long/lat point and I appended all result in one list as below :

out_list=[]
for i in ds.longitude.values:
    for j in ds.latitude.values:
        point = arr.sel(longitude=i,latitude=j)
        
        p_detrend = sm.tsa.tsatools.detrend(point, order=1,axis=0)
        out_list.append(p_detrend)

and my list as below : enter image description here and you can see there are many arrays and each one has long/lat . How to combine all arrays in one dataset by longitude and latitude ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

maybe you could use dictionary instead, something like:

out_list = []

for i in ds.longitude.values:
    for j in ds.latitude.values:
        point = arr.sel(longitude=i,latitude=j)
        p_detrend = sm.tsa.tsatools.detrend(point, order=1,axis=0)

        result = {
            'longitude': i, 
            'latitude': j,
            'detrend_arr': p_detrend  
        }
        out_list.append(result)

then you may use pandas to convert into pd.DataFrame for other manipulation;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...