Skip to content

Instantly share code, notes, and snippets.

@shantanuo
Created July 17, 2020 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shantanuo/f3f9f3586d0e82d62ba271952847fb9d to your computer and use it in GitHub Desktop.
Save shantanuo/f3f9f3586d0e82d62ba271952847fb9d to your computer and use it in GitHub Desktop.
rewrite the code using pandas
# https://www.geodose.com/2020/06/how-to-create-coronavirus-time-series-map.html
import pandas as pd
import numpy as np
df = pd.read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")
df = df.set_index(list(df.columns[:4]))
df = df.stack().reset_index()
df.columns = ["province", "country", "lat", "lon", "date", "n_death"]
df["n_death"] = df["n_death"].replace(0, np.nan)
df = df.dropna(subset=["n_death"])
df["n_death"] = df["n_death"].values.astype(np.int64)
df["new_date"] = pd.to_datetime(df["date"])
df = df.sort_values(["new_date", "country"], ascending=[False, True])
df[["date", "country", "province", "lat", "lon", "n_death"]].to_csv("output_death_300520_new.csv", index=None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment