bindinihh
bindinihh

Reputation: 15

How can I organize this python structure?

[{'id': '1_2003_01_01', 'longitude': -56.6107063111071, 'latitude': -14.196840002932301, 'time': 1041379200000, 'NDVI': 0.7633000000000001}, {'id': '1_2003_01_17', 'longitude': -56.6107063111071, 'latitude': -14.196840002932301, 'time': 1042761600000, 'NDVI': 0.14020000000000002}, ...

I want to sort by 'time', and derive a numpy array of NDVI and another one of EVI, and also the date vector.

Is it possible?

Upvotes: 0

Views: 53

Answers (1)

adir abargil
adir abargil

Reputation: 5745

you can do as in comments and just push it into pandas DataFrame constructor:

import np as numpy
impoty pd as pandas

ld = [{'id': '1_2003_01_01', 'longitude': -56.6107063111071, 'latitude': -14.196840002932301, 'time': 1041379200000, 'NDVI': 0.7633000000000001}, {'id': '1_2003_01_17', 'longitude': -56.6107063111071, 'latitude': -14.196840002932301, 'time': 1042761600000, 'NDVI': 0.14020000000000002}]
df = pd.DataFrame(ld).sort_values('time')

and df yields:


    id              longitude   latitude    time            NDVI
0   1_2003_01_01    -56.610706  -14.19684   1041379200000   0.7633
1   1_2003_01_17    -56.610706  -14.19684   1042761600000   0.1402

u can then call df['NDVI'] and get series or numpy array if u do df['NDVI'].values.

Upvotes: 1

Related Questions