Skip to content

Instantly share code, notes, and snippets.

@phpmaps
Created July 3, 2019 18:39
Show Gist options
  • Select an option

  • Save phpmaps/67337ca30e8d74ee15569e39a0563fca to your computer and use it in GitHub Desktop.

Select an option

Save phpmaps/67337ca30e8d74ee15569e39a0563fca to your computer and use it in GitHub Desktop.
snowfall / s3
import datetime as dt
import pandas as pd
import os
from six.moves import urllib
year = "2019"
## Get the data from the web
path = "ca_snow_feb_{}.csv".format(year)
url = "https://s3-us-west-1.amazonaws.com/python-and-r/ca_snow_feb_{}.csv".format(year)
urllib.request.urlretrieve(url,path)
with open(path,'r') as f:
text = f.readlines()[1:]
text = ''.join([i for i in text])
## Write cleaned data to new CSV file
cleanedPath = "cln_{}".format(path)
with open(cleanedPath, "w+") as txtFile:
print(text, file=txtFile)
df = pd.read_csv(cleanedPath, sep=',')
ndf = df.rename(index=str, columns={"GHCN ID": "GHCN_ID", "Station Name": "Station_Name"})
stations = ndf[['GHCN_ID','Station_Name', 'County', 'Elevation', 'Latitude', 'Longitude']]
stations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment