Created
July 25, 2022 23:31
-
-
Save rtkilian/159fe2e33b25737a66fb84ed2c90b358 to your computer and use it in GitHub Desktop.
Scheduling a Amazon SageMaker Notebook Instance example.
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
# Packages | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import boto3 | |
# Default parameters | |
bucket = 'rtkilian-writing' | |
image_name = 'covid_cumulative_aus_state.png' | |
# Read | |
df = pd.read_csv('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv') | |
# Data processing | |
df_aus = df.loc[df['Country/Region']=='Australia'] # filter for Australia | |
df_aus = df_aus.drop(['Country/Region', 'Lat', 'Long'], axis=1) # remove columns | |
df_aus = df_aus.transpose() # Transpose | |
df_aus = df_aus.rename(columns=df_aus.iloc[0]).drop(df_aus.index[0]) # Put the top row as the heading | |
df_aus.index = pd.to_datetime(df_aus.index) # Convert the index to datetime format | |
df_aus = df_aus[-365:] # last 365 days of data | |
# Visualise | |
ax = df_aus.plot(figsize=(12,6), title='Cumulative COVID-19 Confirmed Cases in Australia by State in the Past Year') | |
plt.show() | |
# Export locally | |
fig = ax.get_figure() | |
fig.savefig(image_name) # save the plot to local volume | |
# Export to S3 | |
key='sagemaker-schedule/'+image_name | |
img_data = open(image_name, 'rb') | |
s3 = boto3.resource('s3') | |
s3.Bucket(bucket).put_object(Key=key, Body=img_data, | |
ContentType='image/png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment