Using a loop and df.query

  Kiến thức lập trình

I have a matrix (17,11).

For each point, I have a several values (go3), because I have 9 rows for each day.

I have to select each “longitude” (it is like axis X) and each “latitude” (its like axis Y), and put all this values on a dataframe, and after that, I have to groupby by day, to obtain the mean value, and export to a csv.

I know how to do one by one.

dl_1=d.query('longitude==-55 and latitude==-18.5')
daily_resampled_data_1 = dl_1.resample('D').mean()
daily_resampled_data_1.to_csv('CAMS_ponto1_O3.csv')
daily_resampled_data_1

But I don’t know how use query in a for-loop.
I need help, to create this loop, to simplify my task.

I expect something like this:

    latitudes = [-18.5, -19.25, -20.0, -20.75, -21.5, -22.25, -23.0, -23.75, -24.5, -25.25,-26.0]
    longitudes = [-55.0, -54.25, -53.5, -52.75, -52.0, -51.25, -50.5, -49.75, -49.0, -48.25, 47.5, -46.75, -46.0, -45.25, -44.5, -43.75, -43.0]

for x in latitude:
       for y in longitude:
           dl_[x][y]=d.query('longitude==[x] and latitude==[y]')
           daily_resampled_data_[x][y] = dl_[x][y].resample('D').mean()
           daily_resampled_data_[x][y].to_csv('CAMS_ponto[x][y]_O3.csv')
           

Is this possible?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT