This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for k, v in today_json['links'].items(): | |
| print("{}: https://data.nba.net{}".format(k ,v)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| response_text = response.text | |
| today_json = json.loads(response_text) | |
| print(type(response_text)) | |
| print(type(today_json)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| request_url = "https://data.nba.net/10s/prod/v3/today.json" | |
| request_headers = { | |
| 'authority': "data.nba.net", | |
| 'method': "GET", | |
| 'path': "/10s/prod/v3/today.json", | |
| 'scheme': "https", | |
| 'accept': "application/json, text/plain, */*", | |
| 'accept-encoding': "gzip, deflate, br", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| def plot_line(ax, country, summary_ser): | |
| country_ser = summary_ser[country] | |
| x = country_ser.index | |
| y = country_ser.values | |
| ax.plot(x, y, marker='o', color='orange') | |
| ax_title = "Total Confirmed in {}".format(country) | |
| ax.set_title(ax_title) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from matplotlib.colors import ListedColormap | |
| from sklearn.datasets import make_moons | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.preprocessing import StandardScaler | |
| from sklearn.neighbors import KNeighborsClassifier | |
| from sklearn.svm import SVC | |
| from sklearn.gaussian_process import GaussianProcessClassifier | |
| from sklearn.gaussian_process.kernels import RBF | |
| from sklearn.tree import DecisionTreeClassifier | |
| from sklearn.ensemble import RandomForestClassifier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def plot_sin(ax_obj, x_arr, y_arr): | |
| ax_obj.plot(x, y) | |
| ax_obj.set_title("$y = sin(x)$") | |
| ax_obj.set_xlabel("x") | |
| ax_obj.set_ylabel("y") | |
| ax_obj.set_xticks([0, np.pi, 2*np.pi]) | |
| ax_obj.set_xticklabels(['0', '$\pi$', '$2\pi$']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| x = np.linspace(0, 2*np.pi) | |
| y = np.sin(x) | |
| fig = plt.figure() | |
| ax = plt.axes() | |
| ax.plot(x, y) | |
| ax.set_title("$y = sin(x)$") | |
| ax.set_xlabel("x") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| x = np.linspace(0, 2*np.pi) | |
| y = np.sin(x) | |
| plt.plot(x, y) | |
| plt.title("$y = sin(x)$") | |
| plt.xlabel("x") | |
| plt.ylabel("y") | |
| plt.xticks([0, np.pi, 2*np.pi],['0', '$\pi$', '$2\pi$']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(ggplot2) | |
| ttl_confirmed_by_date <- ts_long %>% | |
| group_by(Date) %>% | |
| summarise(Confirmed = sum(Confirmed)) %>% | |
| ggplot(aes(x = Date, y = Confirmed)) + | |
| geom_line() + | |
| geom_point() + | |
| ggtitle("Confirmed") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyr) | |
| col_names <- colnames(ts_wide) | |
| date_cols <- col_names[5:length(col_names)] | |
| ts_long <- pivot_longer(ts_wide, cols = date_cols, names_to = "Date", values_to = "Confirmed") | |
| ts_long$Date <- gsub(pattern = "X", replacement = "", ts_long$Date) | |
| ts_long$Date <- as.Date(ts_long$Date, format = "%m.%d.%y") | |
| # 轉置後 | |
| head(ts_long) |