Skip to main content
Added a better map
Source Link
Aaron
  • 51.8k
  • 29
  • 157
  • 322

You can get country centroids using Python and GeoPandas.

import geopandas as gpd
import pandas as pd

# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Get a list (dataframe) of country centroids
centroids = world.centroid
centroid_list = pd.concat([world.name, centroids], axis=1)

# Plot the results
base = world.plot(column = 'name')#, cmap = 'OrRd''Blues')
centroids.plot(ax = base, marker = 'o', color = 'red', markersize = 5)

In [1]: centroid_list
Out[1]: 
                           name                                              0
    0               Afghanistan  POINT (66.08669022192834 33.85639928169076)
    1                    Angola  POINT (17.47057255231345 -12.24586903613316)
    2                   Albania  POINT (20.03242643144321 41.14135330604877)
    3      United Arab Emirates  POINT (54.20671476159633 23.86863365334761)
    4                 Argentina  POINT (-65.17536077114174 -35.44682148949509)
    5                   Armenia  POINT (45.00029001101479 40.21660761230144)
    6                Antarctica  POINT (20.57100056984261 -80.49198288284349)
    ... and so on ...

resultenter image description here

You can get country centroids using Python and GeoPandas.

import geopandas as gpd
import pandas as pd

# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Get a list (dataframe) of country centroids
centroids = world.centroid
centroid_list = pd.concat([world.name, centroids], axis=1)

# Plot the results
base = world.plot(column = 'name')#, cmap = 'OrRd')
centroids.plot(ax = base, marker = 'o', color = 'red', markersize = 5)

In [1]: centroid_list
Out[1]: 
                           name                                              0
    0               Afghanistan  POINT (66.08669022192834 33.85639928169076)
    1                    Angola  POINT (17.47057255231345 -12.24586903613316)
    2                   Albania  POINT (20.03242643144321 41.14135330604877)
    3      United Arab Emirates  POINT (54.20671476159633 23.86863365334761)
    4                 Argentina  POINT (-65.17536077114174 -35.44682148949509)
    5                   Armenia  POINT (45.00029001101479 40.21660761230144)
    6                Antarctica  POINT (20.57100056984261 -80.49198288284349)
    ... and so on ...

result

You can get country centroids using Python and GeoPandas.

import geopandas as gpd
import pandas as pd

# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Get a list (dataframe) of country centroids
centroids = world.centroid
centroid_list = pd.concat([world.name, centroids], axis=1)

# Plot the results
base = world.plot(column = 'name', cmap = 'Blues')
centroids.plot(ax = base, marker = 'o', color = 'red', markersize = 5)

In [1]: centroid_list
Out[1]: 
                           name                                              0
    0               Afghanistan  POINT (66.08669022192834 33.85639928169076)
    1                    Angola  POINT (17.47057255231345 -12.24586903613316)
    2                   Albania  POINT (20.03242643144321 41.14135330604877)
    3      United Arab Emirates  POINT (54.20671476159633 23.86863365334761)
    4                 Argentina  POINT (-65.17536077114174 -35.44682148949509)
    5                   Armenia  POINT (45.00029001101479 40.21660761230144)
    6                Antarctica  POINT (20.57100056984261 -80.49198288284349)
    ... and so on ...

enter image description here

Tiny adjustments
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148
import geopandas as gpd
import pandas as pd

# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Get a list (dataframe) of country centroids
centroids = world.centroid
centroid_list = pd.concat([world.name, centroids], axis=1)

# Plot the results
base = world.plot(column = 'name')#, cmap = 'OrRd')
centroids.plot(ax = base, marker = 'o', color = 'red', markersize = 5)
import geopandas as gpd
import pandas as pd

# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Get a list (dataframe) of country centroids
centroids = world.centroid
centroid_list = pd.concat([world.name, centroids], axis=1)

# Plot the results
base = world.plot(column = 'name')#, cmap = 'OrRd')
centroids.plot(ax = base, marker = 'o', color = 'red', markersize = 5)
In [1]: centroid_list
Out[1]: 
                           name                                              0
    0               Afghanistan    POINT (66.08669022192834 33.85639928169076)
    1                    Angola   POINT (17.47057255231345 -12.24586903613316)
    2                   Albania    POINT (20.03242643144321 41.14135330604877)
    3      United Arab Emirates    POINT (54.20671476159633 23.86863365334761)
    4                 Argentina  POINT (-65.17536077114174 -35.44682148949509)
    5                   Armenia    POINT (45.00029001101479 40.21660761230144)
    6                Antarctica   POINT (20.57100056984261 -80.49198288284349)
    ... and so on ...
In [1]: centroid_list
Out[1]: 
                           name                                              0
    0               Afghanistan  POINT (66.08669022192834 33.85639928169076)
    1                    Angola  POINT (17.47057255231345 -12.24586903613316)
    2                   Albania  POINT (20.03242643144321 41.14135330604877)
    3      United Arab Emirates  POINT (54.20671476159633 23.86863365334761)
    4                 Argentina  POINT (-65.17536077114174 -35.44682148949509)
    5                   Armenia  POINT (45.00029001101479 40.21660761230144)
    6                Antarctica  POINT (20.57100056984261 -80.49198288284349)
    ... and so on ...

enter image description hereresult

import geopandas as gpd
import pandas as pd

# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Get a list (dataframe) of country centroids
centroids = world.centroid
centroid_list = pd.concat([world.name, centroids], axis=1)

# Plot the results
base = world.plot(column = 'name')#, cmap = 'OrRd')
centroids.plot(ax = base, marker = 'o', color = 'red', markersize = 5)
In [1]: centroid_list
Out[1]: 
                           name                                              0
    0               Afghanistan    POINT (66.08669022192834 33.85639928169076)
    1                    Angola   POINT (17.47057255231345 -12.24586903613316)
    2                   Albania    POINT (20.03242643144321 41.14135330604877)
    3      United Arab Emirates    POINT (54.20671476159633 23.86863365334761)
    4                 Argentina  POINT (-65.17536077114174 -35.44682148949509)
    5                   Armenia    POINT (45.00029001101479 40.21660761230144)
    6                Antarctica   POINT (20.57100056984261 -80.49198288284349)
    ... and so on ...

enter image description here

import geopandas as gpd
import pandas as pd

# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Get a list (dataframe) of country centroids
centroids = world.centroid
centroid_list = pd.concat([world.name, centroids], axis=1)

# Plot the results
base = world.plot(column = 'name')#, cmap = 'OrRd')
centroids.plot(ax = base, marker = 'o', color = 'red', markersize = 5)
In [1]: centroid_list
Out[1]: 
                           name                                              0
    0               Afghanistan  POINT (66.08669022192834 33.85639928169076)
    1                    Angola  POINT (17.47057255231345 -12.24586903613316)
    2                   Albania  POINT (20.03242643144321 41.14135330604877)
    3      United Arab Emirates  POINT (54.20671476159633 23.86863365334761)
    4                 Argentina  POINT (-65.17536077114174 -35.44682148949509)
    5                   Armenia  POINT (45.00029001101479 40.21660761230144)
    6                Antarctica  POINT (20.57100056984261 -80.49198288284349)
    ... and so on ...

result

Source Link
Aaron
  • 51.8k
  • 29
  • 157
  • 322

You can get country centroids using Python and GeoPandas.

import geopandas as gpd
import pandas as pd

# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Get a list (dataframe) of country centroids
centroids = world.centroid
centroid_list = pd.concat([world.name, centroids], axis=1)

# Plot the results
base = world.plot(column = 'name')#, cmap = 'OrRd')
centroids.plot(ax = base, marker = 'o', color = 'red', markersize = 5)

In [1]: centroid_list
Out[1]: 
                           name                                              0
    0               Afghanistan    POINT (66.08669022192834 33.85639928169076)
    1                    Angola   POINT (17.47057255231345 -12.24586903613316)
    2                   Albania    POINT (20.03242643144321 41.14135330604877)
    3      United Arab Emirates    POINT (54.20671476159633 23.86863365334761)
    4                 Argentina  POINT (-65.17536077114174 -35.44682148949509)
    5                   Armenia    POINT (45.00029001101479 40.21660761230144)
    6                Antarctica   POINT (20.57100056984261 -80.49198288284349)
    ... and so on ...

enter image description here