avatarDi(Candice) Han

Summary

This web content provides a tutorial on creating a Nightingale Rose chart in Python to visualize the Covid-19 death rate using the Pyechart library, demonstrating the process from data acquisition to chart generation.

Abstract

The article guides readers through the process of visualizing Covid-19 death rates using a Nightingale Rose chart, a circular graph that combines radar and column graph elements. It begins by acknowledging Florence Nightingale's contribution to statistical graphics and then proceeds with a step-by-step Python-based approach. The tutorial covers importing necessary libraries, acquiring data from the Worldometers website, data manipulation to calculate death rates, and finally, generating the rose chart to represent the top 15 countries with the highest death rates. The use of the Pyechart library is central to the tutorial, and the resulting visualization is both informative and aesthetically pleasing, providing insights into the impact of the pandemic.

Opinions

  • The author emphasizes the historical significance of Florence Nightingale's work in data visualization and its relevance to contemporary data analysis.
  • The tutorial suggests that the Worldometers website is a reliable source for Covid-19 data due to its daily updates and well-structured format.
  • The author highlights the practicality of using Python's Pandas library and its read_clipboard() function for quick data manipulation, despite its limitation with merged cells.
  • The article conveys the importance of data preprocessing, such as handling missing values, converting data types, and calculating derived metrics like death rates.
  • The choice of colors and the design of the rose chart are presented as crucial elements for making the visualization both engaging and informative.
  • The author encourages readers to stay at home and learn data visualization during the pandemic, suggesting a productive use of time during lockdowns.
  • The article promotes further exploration of data visualization by providing links to other tutorials on creating various types of charts in Python.

Make a Beautiful Nightingale Rose Chart in Python

Visualize Covid-19 Death Rate

Nightingale’s Rose chart, also referred to as “polar area chart” or “coxcomb chart”, is a circular graph that combines elements of a radar chart and a column graph. This special chart is named after a nurse, statistician, and reformer Florence Nightingale. She invented a color statistical graphic entitled “Diagram of the Causes of Mortality in the Army of the East” to dramatize the extent of needless deaths in British military hospitals during the Cirmean War (1954–56). The chart showed that epidemic disease was responsible for more British deaths in the course of the war than battlefield wounds.

This tutorial, we will create a Nightingale rose chart in Python using the Pyechart library. We don’t even need to import data! It only takes few steps, and you will have a rose chart like this!

Nightinggale Rose Chart

Step 1: import libraries

import numpy as np
import pandas as pd
from pyecharts.charts import Pie
from pyecharts import options as opts

Step 2: open the website and get data by clipboard function

import webbrowser
website = ‘https://www.worldometers.info/coronavirus/'
webbrowser.open(website)

Worldmeters refreshes covid-19 information daily with a good format, so data for this tutorial is from this website. read_clipboard() in Pandas can read, copy, paste tabular data and parse it into a Data Frame. It is a very useful function if you want to practice on small dataset. One of the limitation is that it cannot handle merged cells.

Snapshot from worldmeters.info

When you copy the table from Worldmeters, please do not include the first row, which has column names. Each cell in the first row is merged cell and clipboard() cannot process it. It will return error.

After you copy the whole table except the first row, execute below codes

data = pd.read_clipboard()
data

You will get a table like this

Step3: the first row will be replaced by proper column names

data.columns = [‘Country’,’TotalCases’,’NewCases’,’TotalDeaths’,’NewDeaths’,’TotalRecovered’,’ActiveCases’,’CriticalCondition’,‘TotCasesPerMillion’,’DeathsPerMillion’,’TotalTests’,’TestsPerMillion’]
data

Then, the dataframe looks much better.

Step 4: data manipulation

# remove "," from the dataset
for x in range(1,len(data.columns)):
 data[data.columns[x]] = data[data.columns[x]].str.replace(‘,’,’’) 
#replace NaNs with zeros
data = data.fillna(0)
#change the datatype from object to integer
for i in range (1,len(data.columns)):
    data[data.columns[i]] = data[data.columns[i]].astype(float).astype(int)
#create a column 'Death Rate'
data['DeathRate'] = data['TotalDeaths']/data['TotalCases']
#sort the data frame by 'Death Rate' in descending order
data.sort_values(by=['DeathRate'], inplace=True, ascending=False)

Step 5: Select the top 15 countries which have the highest death rate

df=data[[‘Country’,’DeathRate’]].head(15) #select two columns and top 15 rows
df[‘DeathRate’] = (df[‘DeathRate’]*100).round(1)
df

The data frame for further visualization is ready.

Step 6: visualize the data

c = df[‘Country’].values.tolist()
d = df[‘DeathRate’].values.tolist()
#create the color_series for the rosechart
color_series = [‘#802200’,’#B33000',’#FF4500',’#FAA327',’#9ECB3C’,
 ‘#6DBC49’,’#37B44E’,’#14ADCF’,’#209AC9',’#1E91CA’,
 ‘#2C6BA0’,’#2B55A1',’#2D3D8E’,’#44388E’,’#6A368B’,
 ‘#D02C2A’,’#D44C2D’,’#F57A34',’#FA8F2F’,’#D99D21']
rosechart = Pie(init_opts=opts.InitOpts(width='1350px', height='750px'))
# set the color
rosechart.set_colors(color_series)
# add the data to the rosechart
rosechart.add("", [list(z) for z in zip(c, d)],
        radius=["20%", "95%"],  # 20% inside radius,95% ourside radius
        center=["30%", "60%"],   # center of the chart
        rosetype="area")
# set the global options for the chart
rosechart.set_global_opts(title_opts=opts.TitleOpts(title='Nightingale Rose Chart',subtitle="Covid-19 Death Rate"),
                     legend_opts=opts.LegendOpts(is_show=False),
                     toolbox_opts=opts.ToolboxOpts())
# set the series options
rosechart.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position="inside", font_size=12,formatter="{b}:{c}%", font_style="italic",font_weight="bold", font_family="Century"),)
rosechart.render_notebook()

Finally, the beautiful Nightingale rose chart is generated!

From the chart, it is easy to see that the MS Zaandam, which is a cruise ship, has the highest death rate. Next to it are Burundi, Bahamas and Sudan. And the death rates of the top 15 countries all exceeded 10%, considerably higher than the death rate of normal seasonal flu, which is typically around 0.1% in the U.S., according to The New York Times.

So, stay at home and enjoy learning data visualization!

If you are interested in making other types of beautiful charts, you may want to check out my other posts.

  1. Make a beautiful water polo chart in a few lines in Python
  2. Make a beautiful bar chart in just few lines in Python
  3. Make a beautiful scatterplot in a few lines in Python to make your report outstanding
  4. Make an impressive animated bubble chart with Plotly in Python — inspired by professor Hans Rosling
  5. Make the cutest chart in Python — visualize your data with hand-drawn charts
Python
Python3
Pie Charts
Data Visualization
Covid-19
Recommended from ReadMedium