GIS analysis been one of upcoming data analysis in world that is providing solution to spatial problem and environmental problems has made a great shift in statistical world.Data collaboration has improved data visualization through use of map and chart in representing data.
In this post I shall illustrate on how corona data from John Hopkins University data collection in form of csv file is merged with spatial world data to form a spatial data (geojson,shp).
Programming language used is python,this is effective as GIS software use spatial data only and non-spatial data cannot be used.This post creates data harmonisation.
Python libraries used are Pandas and Geopandas
First we merge the csv file with the world map shp(for all confirmed,death and recovery data)
#import python libraries
#get the required data
#data merging
#data exporting
Algothim above can be used to create data for other data for other continent.
I will attach the code and data together with images.
In this post I shall illustrate on how corona data from John Hopkins University data collection in form of csv file is merged with spatial world data to form a spatial data (geojson,shp).
Programming language used is python,this is effective as GIS software use spatial data only and non-spatial data cannot be used.This post creates data harmonisation.
Python libraries used are Pandas and Geopandas
First we merge the csv file with the world map shp(for all confirmed,death and recovery data)
#import python libraries
- Code:
import pandas as pd
import geopandas as gpd
#get the required data
- Code:
confirmed=('csse_covid_19_time_series_confirmed_global.csv')
death=('time_series_covid19_deaths_global.csv')
recovered=('time_series_covid19_recovered_global.csv')
world = gpd.read_file('world.geojson')
data_cont = pd.read_csv('Countries-Continents.csv')
#data merging
- Code:
# csv file
data_confirmed = pd.read_csv(confirmed)
data_confirmed = data_confirmed[['Country/Region',data_confirmed.columns[-1]]]
data_confirmed.columns = ['country','confirmed']
data_confirmed.head(10)
- Code:
# continent data
data_cont.columns = ['continent','country']
data_merge_confirmed_cont = pd.merge(left=data_cont, right=data_confirmed,
how='left', right_on='country',
left_on='country')
data_merge_confirmed_cont.head(10)
- Code:
# world spatial data
world = gpd.read_file('world.geojson')
world = world[['NAME','geometry']]
world.columns = ['country','geometry']
world.plot(figsize=(15,20),color='white',edgecolor='black')
- Code:
# data merging
data_merge_confirmed = pd.merge(left=data_merge_confirmed_cont,
right=world, how='left',
left_on='country', right_on='country'
)
data_merge_confirmed.head(10)
- Code:
# data transformation from dataframe to geodataframe
geo_data_confirmed = gpd.GeoDataFrame(data_merge_confirmed)
- Code:
# selecting Africa
africa_confirmed = geo_data_confirmed[geo_data_confirmed['continent']=='Africa']
# plot Africa data
africa_confirmed.plot(figsize=(7,10),color='white',edgecolor='black')
- Code:
africa_confirmed.head(10)
#data exporting
- Code:
# geojson
africa_confirmed.to_file("africa_confirmed.geojson",driver='GeoJSON')
# shp
africa_confirmed.to_file("africa_confirmed.shp")
# csv
africa_confirmed.to_file("africa_confirmed.csv")
# excel
africa_confirmed.to_file("africa_confirmed.xslx")
Algothim above can be used to create data for other data for other continent.
I will attach the code and data together with images.