<jupyter_start><jupyter_text>Loading COVID-19 Data to Google Sheet---In this project, we read COVID-19 coronavirus data available from [World Health Organization](https://covid19.who.int/) and load it into Google Sheet, where this is one of the data sources used for a [data visualisation work](https://public.tableau.com/profile/peggy.chang!/vizhome/COVID-19Updates_16082983614350/S1) created for COVID-19 updates on **Tableau Public**.![Tableau](Tableau.png)**Tool:**To load COVID-19 data onto Google Sheet, we use [`pygsheets`](https://pygsheets.readthedocs.io/en/latest/) written by [<NAME>](https://github.com/nithinmurali/pygsheets). This is a simple, intuitive Python library to access Google spreadsheets through the Google Sheets API v4.Although we can use the `importData()` function in Google Sheet itself to obtain data directly from a URL, there are some limitations and it would not work for large datasets.**Pre-requisite:**Before running the codes below, we first need to go to [Google Developer Console](https://console.developers.google.com/) to enable the Google Drive API, create a service account and download the private key in a JSON file for account authorization.We will also need to share the specific Google Sheet with the service account email address.<jupyter_code>import pygsheets
import pandas as pd
import datetime as dt

### Authorizing pygsheets.

gc = pygsheets.authorize(service_file='client_secret.json')
### Open an existing Google Sheet by key and clear its content.

sh = gc.open_by_key('<KEY>') # WHO_Covid19_GS

wks = sh.worksheet(property='index', value=0)   # value=0 means first tab

wks.clear()
### Get source data from WHO website.

url = "https://covid19.who.int/WHO-COVID-19-global-data.csv"

df = pd.read_csv(url, parse_dates=['Date_reported'])

### Check the number of rows and columns.

df.shape
df.describe()
### Check the column data type.

df.info()
### Convert the format of 'Date_reported' to dd/mm/yyyy.

df['Date_reported'] = df['Date_reported'].dt.strftime("%d/%m/%Y")
### Check the last 5 records to ensure that we're getting up-to-date data.

df.tail()
df[df["Country_code"]=="SG"].tail()
### Write the data from Pandas dataframe to Google Sheet.

wks.set_dataframe(df, start='A1', copy_index=False, copy_head=True, fit=True, escape_formulae=False, nan=0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11631870472944184, 'fraction_numerical': 0.016616957818491693, 'mean_word_length': 5.328840970350404, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '405629', 'license': 'MIT', 'n_tokens_mistral': 754, 'n_tokens_neox': 698, 'n_words': 253, 'path': 'Project_WHO_GoogleSheet.ipynb', 'repo_name': 'peggy1502/Load-Data-To-GoogleSheet', 'size': '2393'}