I am trying to use the Covid-19 Dataset to build an SIR model. In order to build this model, I require the population of each location (country or province/state and/or county) to calculate the S (susceptible) in SIR. Since this dataset does not contain population data, I thought it would be good to do this using an API. I came across countryinfo, but the population estimates have not been updated since 2018 (according to the example and pypi); Also, one must be careful when entering country names as the ones accepted by countryinfo
are not necessarily the same as those provided in the dataset.
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
p = country.population()
print(p)
# 5469700
country = CountryInfo('United States')
# country = CountryInfo('US') # is not accepted
p = country.population()
print(p)
# 319259000
I can type generic queries (ie, type "US"
or "United States"
) into google to find the population of any location, but I am not sure how to do this programmatically in python. Typing 'us'
in-place of location
below will show the US population (via this solution).
query = 'https://www.google.com/search?q=' + location + 'population
I think the wikipedia API can be used to the same effect, but I am not quite sure how to do this. Is there a better way? If not, how can I use wikipedia
to get the population from a queried location?