I have the following list of geographic coordinates organize in 2 mains blocks corresponding to 2 polygons :
[[[31.547836, -103.7842], [31.639685, -104.03722], [32.051894, -104.22097], [32.082813, -104.20363], [32.195333, -104.10359], [32.398168, -103.66786], [32.224538, -103.48232], [31.977848, -103.28086], [31.8019236, -103.30381], [31.688412, -103.482903], [31.607474, -103.62303]], [[31.582053, -101.93924], [31.585542, -102.16106], [31.6131197, -102.24417], [31.661732, -102.2972], [32.0562417, -102.28902], [32.4380094, -101.97873], [32.438598, -101.94766], [32.435146, -101.83021], [32.4000907, -101.78283], [31.905481, -101.73379], [31.781019, -101.72468], [31.650047, -101.71616], [31.6497171, -101.71621], [31.583703, -101.80637]]]
I would like to break this list in 2 dataframes (corresponding to the 2 blocks delimiter by double “[“) with latitude and longitude columns.
Ex : first dataframe df :
latitude longitude 31.547836 -103.7842 ... ...
Second one df 1 :
latitude longitude 31.582053 -101.93924 ... ...
Advertisement
Answer
Try this:
import pandas as pd df1 = pd.DataFrame(lst[0], columns=['latitude', 'longitude']) df2 = pd.DataFrame(lst[1], columns=['latitude', 'longitude']) print(df1) print(df2)
Output:
# => df1 latitude longitude 0 31.547836 -103.784200 1 31.639685 -104.037220 2 32.051894 -104.220970 3 32.082813 -104.203630 4 32.195333 -104.103590 5 32.398168 -103.667860 6 32.224538 -103.482320 7 31.977848 -103.280860 8 31.801924 -103.303810 9 31.688412 -103.482903 10 31.607474 -103.623030 # => df2 latitude longitude 0 31.582053 -101.93924 1 31.585542 -102.16106 2 31.613120 -102.24417 3 31.661732 -102.29720 4 32.056242 -102.28902 5 32.438009 -101.97873 6 32.438598 -101.94766 7 32.435146 -101.83021 8 32.400091 -101.78283 9 31.905481 -101.73379 10 31.781019 -101.72468 11 31.650047 -101.71616 12 31.649717 -101.71621 13 31.583703 -101.80637