<jupyter_start><jupyter_text>[Warming Up!](https://academy.dqlab.id/main/livecode/287/531/2651)<jupyter_code>bersatulawancovid = ['cuci tangan', 'pakai masker', 'jaga jarak']
print(bersatulawancovid)<jupyter_output>['cuci tangan', 'pakai masker', 'jaga jarak']<jupyter_text>[Are You Ready?](https://academy.dqlab.id/main/livecode/287/531/2652)<jupyter_code>True<jupyter_output><empty_output><jupyter_text>[Mengakses API covid19.go.id](https://academy.dqlab.id/main/livecode/287/532/2653)<jupyter_code>import requests
resp = requests.get('https://data.covid19.go.id/public/api/update.json')<jupyter_output><empty_output><jupyter_text>[Status Code](https://academy.dqlab.id/main/livecode/287/532/2656)<jupyter_code>print(resp)<jupyter_output><Response [200]><jupyter_text>[Headers API](https://academy.dqlab.id/main/livecode/287/532/2657)<jupyter_code>print(resp.headers)<jupyter_output>{'Server': 'nginx', 'Date': 'Tue, 26 Jan 2021 13:34:34 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding, Accept-Encoding', 'Last-Modified': 'Tue, 26 Jan 2021 13:31:47 GMT', 'ETag': 'W/"601019c3-1f014"', 'X-Content-Type-Options': 'nosniff, nosniff', 'X-XSS-Protection': '1; mode=block, 1; mode=block', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Content-Encoding': 'gzip'}<jupyter_text>[Mengekstrak Isi Respon](https://academy.dqlab.id/main/livecode/287/532/2658)<jupyter_code>cov_id_raw  = resp.json()<jupyter_output><empty_output><jupyter_text>[Mengekstrak isi Respon - 2](https://academy.dqlab.id/main/livecode/287/532/2659)<jupyter_code>print('Length of cov_id_raw : %d.' %len(cov_id_raw))
print('Komponen cov_id_raw  : %s.' %cov_id_raw.keys())
cov_id_update = cov_id_raw['update']<jupyter_output>Length of cov_id_raw : 2.
Komponen cov_id_raw  : dict_keys(['data', 'update']).<jupyter_text>[Analisa Data](https://academy.dqlab.id/main/livecode/287/532/2660)<jupyter_code>print('Tanggal pembaharuan data penambahan kasus :', cov_id_update['penambahan']['tanggal'])
print('Jumlah penambahan kasus sembuh :', cov_id_update['penambahan']['jumlah_sembuh'])
print('Jumlah penambahan kasus meninggal :', cov_id_update['penambahan']['jumlah_meninggal'])
print('Jumlah total kasus positif hingga saat ini :', cov_id_update['total']['jumlah_positif'])
print('Jumlah total kasus meninggal hingga saat ini:', cov_id_update['total']['jumlah_meninggal'])<jupyter_output>Tanggal pembaharuan data penambahan kasus : 2021-01-26
Jumlah penambahan kasus sembuh : 10868
Jumlah penambahan kasus meninggal : 336
Jumlah total kasus positif hingga saat ini : 1012350
Jumlah total kasus meninggal hingga saat ini: 28468<jupyter_text>[Apa Kabar Jawa Barat?](https://academy.dqlab.id/main/livecode/287/533/2662)<jupyter_code>import requests
resp_jabar = requests.get('https://data.covid19.go.id/public/api/prov_detail_JAWA_BARAT.json')
cov_jabar_raw = resp_jabar.json()<jupyter_output><empty_output><jupyter_text>[Memahami Kasus COVID-19 di Jawa Barat](https://academy.dqlab.id/main/livecode/287/533/2663)<jupyter_code>print('Nama-nama elemen utama:\n', cov_jabar_raw.keys())
print('\nJumlah total kasus COVID-19 di Jawa Barat : %d' %cov_jabar_raw['kasus_total'])
print('Persentase kematian akibat COVID-19 di Jawa Barat : %f.2%%' %cov_jabar_raw['meninggal_persen'])
print('Persentase tingkat kesembuhan dari COVID-19 di Jawa Barat : %f.2%%' %cov_jabar_raw['sembuh_persen'])<jupyter_output>Nama-nama elemen utama:
 dict_keys(['last_date', 'provinsi', 'kasus_total', 'kasus_tanpa_tgl', 'kasus_dengan_tgl', 'meninggal_persen', 'meninggal_tanpa_tgl', 'meninggal_dengan_tgl', 'sembuh_persen', 'sembuh_tanpa_tgl', 'sembuh_dengan_tgl', 'list_perkembangan', 'data'])

Jumlah total kasus COVID-19 di Jawa Barat : 127398
Persentase kematian akibat COVID-19 di Jawa Barat : 1.193111.2%
Persentase tingkat kesembuhan dari COVID-19 di Jawa Barat : 81.578989.2%<jupyter_text>[Memperoleh Informasi yang Lebih Lengkap](https://academy.dqlab.id/main/livecode/287/533/2664)<jupyter_code>import numpy as np
import pandas as pd
cov_jabar = pd.DataFrame(cov_jabar_raw['list_perkembangan'])
print('Info cov_jabar:\n', cov_jabar.info())
print('\nLima data teratas cov_jabar:\n', cov_jabar.head())<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 330 entries, 0 to 329
Data columns (total 9 columns):
 #   Column                        Non-Null Count  Dtype
---  ------                        --------------  -----
 0   tanggal                       330 non-null    int64
 1   KASUS                         330 non-null    int64
 2   MENINGGAL                     330 non-null    int64
 3   SEMBUH                        330 non-null    int64
 4   DIRAWAT_OR_ISOLASI            330 non-null    int64
 5   AKUMULASI_KASUS               330 non-null    int64
 6   AKUMULASI_SEMBUH              330 non-null    int64
 7   AKUMULASI_MENINGGAL           330 non-null    int64
 8   AKUMULASI_DIRAWAT_OR_ISOLASI  330 non-null    int64
dtypes: int64(9)
memory usage: 23.3 KB
Info cov_jabar:
 None

Lima data teratas cov_jabar:
          tanggal  KASUS  MENINGGAL  SEMBUH  DIRAWAT_OR_ISOLASI  \
0  1583107200000      3          0       0                   3   
1  1583193600000      1          1       0   [...]<jupyter_text>[Menjinakkan Data](https://academy.dqlab.id/main/livecode/287/533/2665)<jupyter_code>cov_jabar_tidy = (cov_jabar.drop(columns=[item for item in cov_jabar.columns
																if item.startswith('AKUMULASI')
																or item.startswith('DIRAWAT')])
												.rename(columns=str.lower)
												.rename(columns={'kasus': 'kasus_baru'})
				  )
cov_jabar_tidy['tanggal'] = pd.to_datetime(cov_jabar_tidy['tanggal']*1e6, unit='ns')
print('Lima data teratas:\n', cov_jabar_tidy.head())<jupyter_output>Lima data teratas:
      tanggal  kasus_baru  meninggal  sembuh
0 2020-03-02           3          0       0
1 2020-03-03           1          1       0
2 2020-03-04           1          0       0
3 2020-03-05           1          0       0
4 2020-03-06           1          0       0<jupyter_text>[Menunjukkan Melalui Gambar](https://academy.dqlab.id/main/livecode/287/533/2666)<jupyter_code>import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>[Menunjukkan Melalui Gambar - 2](https://academy.dqlab.id/main/livecode/287/533/2667)<jupyter_code>import matplotlib.pyplot as plt

plt.clf()
fig, ax = plt.subplots(figsize=(10,5))
ax.bar(data=cov_jabar_tidy, x='tanggal', height='kasus_baru')
plt.show()<jupyter_output><empty_output><jupyter_text>[Informasi pada Grafik](https://academy.dqlab.id/main/livecode/287/533/2668)<jupyter_code>import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.clf()
fig, ax = plt.subplots(figsize=(10,5))
ax.bar(data=cov_jabar_tidy, x='tanggal', height='kasus_baru', color='salmon')
fig.suptitle('Kasus Harian Positif COVID-19 di Jawa Barat',
y=1.00, fontsize=16, fontweight='bold', ha='center')
ax.set_title('Terjadi pelonjakan kasus di awal bulan Juli akibat klaster Secapa AD Bandung',
fontsize=10)
ax.set_xlabel('')
ax.set_ylabel('Jumlah kasus')
ax.text(1, -0.1, 'Sumber data: covid.19.go.id', color='blue',
		ha='right', transform=ax.transAxes)

ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))

plt.grid(axis='y')
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>[Grafik untuk Kasus Sembuh](https://academy.dqlab.id/main/livecode/287/533/2669)<jupyter_code>import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.clf()
fig, ax = plt.subplots(figsize=(10,5))
ax.bar(data=cov_jabar_tidy, x='tanggal', height='sembuh', color='olivedrab')
ax.set_title('Kasus Harian Sembuh Dari COVID-19 di Jawa Barat',
fontsize=22)
ax.set_xlabel('')
ax.set_ylabel('Jumlah kasus')
ax.text(1, -0.1, 'Sumber data: covid.19.go.id', color='blue',
ha='right', transform=ax.transAxes)

ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))

plt.grid(axis='y')
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>[Grafik untuk Kasus Meninggal](https://academy.dqlab.id/main/livecode/287/533/2670)<jupyter_code>import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.clf()
fig, ax = plt.subplots(figsize=(10,5))
ax.bar(data=cov_jabar_tidy, x='tanggal', height='meninggal', color='slategrey')
ax.set_title('Kasus Harian Meninggal Dari COVID-19 di Jawa Barat',
fontsize=22)
ax.set_xlabel('')
ax.set_ylabel('Jumlah kasus')
ax.text(1, -0.1, 'Sumber data: covid.19.go.id', color='blue',
ha='right', transform=ax.transAxes)

ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))

plt.grid(axis='y')
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>[Apakah Pekan ini Lebih Baik?](https://academy.dqlab.id/main/livecode/287/535/2671)<jupyter_code>cov_jabar_pekanan = (cov_jabar_tidy.set_index('tanggal')['kasus_baru']
					  .resample('W')
					  .sum()
					  .reset_index()
					  .rename(columns={'kasus_baru': 'jumlah'})
)
cov_jabar_pekanan['tahun'] = cov_jabar_pekanan['tanggal'].apply(lambda x: x.year)
cov_jabar_pekanan['pekan_ke'] = cov_jabar_pekanan['tanggal'].apply(lambda x: x.weekofyear)
cov_jabar_pekanan = cov_jabar_pekanan[['tahun', 'pekan_ke', 'jumlah']]

print('Info cov_jabar_pekanan:')
print(cov_jabar_pekanan.info())
print('\nLima data teratas cov_jabar_pekanan:\n', cov_jabar_pekanan.head())<jupyter_output>Info cov_jabar_pekanan:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 48 entries, 0 to 47
Data columns (total 3 columns):
 #   Column    Non-Null Count  Dtype
---  ------    --------------  -----
 0   tahun     48 non-null     int64
 1   pekan_ke  48 non-null     int64
 2   jumlah    48 non-null     int64
dtypes: int64(3)
memory usage: 1.2 KB
None

Lima data teratas cov_jabar_pekanan:
    tahun  pekan_ke  jumlah
0   2020        10       7
1   2020        11       5
2   2020        12      52
3   2020        13     104
4   2020        14     122<jupyter_text>[Menjawab Pertanyaan](https://academy.dqlab.id/main/livecode/287/535/2672)<jupyter_code>cov_jabar_pekanan['jumlah_pekanlalu'] = cov_jabar_pekanan['jumlah'].shift().replace(np.nan, 0).astype(np.int)
cov_jabar_pekanan['lebih_baik'] = cov_jabar_pekanan['jumlah'] < cov_jabar_pekanan['jumlah_pekanlalu']

print('Sepuluh data teratas:\n', cov_jabar_pekanan.head(10))<jupyter_output>Sepuluh data teratas:
    tahun  pekan_ke  jumlah  jumlah_pekanlalu  lebih_baik
0   2020        10       7                 0       False
1   2020        11       5                 7        True
2   2020        12      52                 5       False
3   2020        13     104                52       False
4   2020        14     122               104       False
5   2020        15     235               122       False
6   2020        16     277               235       False
7   2020        17     216               277        True
8   2020        18     156               216        True
9   2020        19     367               156       False<jupyter_text>[Membuat Bar Chart](https://academy.dqlab.id/main/livecode/287/535/2673)<jupyter_code>import matplotlib.pyplot as plt

plt.clf()
fig, ax = plt.subplots(figsize=(10,5))
ax.bar(data=cov_jabar_pekanan, x='pekan_ke', height='jumlah',
color=['mediumseagreen' if x is True else 'salmon' for x in cov_jabar_pekanan['lebih_baik']])
fig.suptitle('Kasus Pekanan Positif COVID-19 di Jawa Barat',
y=1.00, fontsize=16, fontweight='bold', ha='center')
ax.set_title('Kolom hijau menunjukan penambahan kasus baru lebih sedikit dibandingkan satu pekan sebelumnya',
fontsize=12)
ax.set_xlabel('')
ax.set_ylabel('Jumlah kasus')
ax.text(1, -0.1, 'Sumber data: covid.19.go.id', color='blue',
ha='right', transform=ax.transAxes)

plt.grid(axis='y')
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>[Pola dan Dinamika](https://academy.dqlab.id/main/livecode/287/535/2674)<jupyter_code>cov_jabar_akumulasi = cov_jabar_tidy[['tanggal']].copy()
cov_jabar_akumulasi['akumulasi_aktif'] = (cov_jabar_tidy['kasus_baru'] - cov_jabar_tidy['sembuh'] - cov_jabar_tidy['meninggal']).cumsum()
cov_jabar_akumulasi['akumulasi_sembuh'] = cov_jabar_tidy['sembuh'].cumsum()
cov_jabar_akumulasi['akumulasi_meninggal'] = cov_jabar_tidy['meninggal'].cumsum()
cov_jabar_akumulasi.tail()<jupyter_output><empty_output><jupyter_text>[Membuat Line Chart](https://academy.dqlab.id/main/livecode/287/535/2675)<jupyter_code>import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.clf()
fig, ax = plt.subplots(figsize=(10,5))
ax.plot('tanggal', 'akumulasi_aktif', data=cov_jabar_akumulasi, lw=2)

ax.set_title('Akumulasi aktif COVID-19 di Jawa Barat',
fontsize=22)
ax.set_xlabel('')
ax.set_ylabel('Akumulasi aktif')
ax.text(1, -0.1, 'Sumber data: covid.19.go.id', color='blue',
ha='right', transform=ax.transAxes)

ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))

plt.grid()
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>[Kabar Buruk dan Kabar Baik](https://academy.dqlab.id/main/livecode/287/535/2676)<jupyter_code>True<jupyter_output><empty_output><jupyter_text>[Tahap Terakhir](https://academy.dqlab.id/main/livecode/287/535/2677)<jupyter_code>import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.clf()
fig, ax = plt.subplots(figsize=(10,5))
cov_jabar_akumulasi.plot(x='tanggal', kind='line', ax=ax, lw=3,
color=['salmon', 'slategrey', 'olivedrab'])

ax.set_title('Dinamika Kasus COVID-19 di Jawa Barat',
fontsize=22)
ax.set_xlabel('')
ax.set_ylabel('Akumulasi aktif')
ax.text(1, -0.1, 'Sumber data: covid.19.go.id', color='blue',
ha='right', transform=ax.transAxes)

ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b'))

plt.grid()
plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14402232238677828, 'fraction_numerical': 0.05780925806682407, 'mean_word_length': 4.413632842757552, 'pattern_counts': {'":': 0, '<': 91, '<?xml version=': 0, '>': 90, 'https://': 26, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '24', 'dir': 'jupyter-structured-clean-dedup', 'id': '192309', 'license': 'MIT', 'n_tokens_mistral': 6398, 'n_tokens_neox': 5613, 'n_words': 896, 'path': 'Learn/Python/Applied Data Science/Eksplorasi dan Analisis Data COVID-19 Indonesia using Python/Eksplorasi dan Analisis Data COVID-19 Indonesia using Python.ipynb', 'repo_name': 'Fathonidear22/DQLab-1', 'size': '13977'}