-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_ETL_job.py
50 lines (31 loc) · 1.22 KB
/
01_ETL_job.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import logging
import pandas as pd
from sodapy import Socrata
from datetime import datetime
now = datetime.now()
def extract_from_api():
logging.basicConfig(level=logging.INFO)
client = Socrata("data.cityofnewyork.us", None)
# Unauthenticated client only works with public data sets. Note 'None'
# in place of application token, and no username or password:
results = client.get("wewp-mm3p", limit=100)
# Convert to pandas DataFrame
results_df = pd.DataFrame.from_records(results)
print(results_df.dtypes)
print(results_df.shape)
print(results_df.head(5))
return results_df
def transform_data(im_extracted):
print(im_extracted['agency_name'].value_counts())
# Filter just after Department of finance data
ex_extracted = im_extracted.loc[im_extracted['agency_name']=="Department of Finance"]
print(ex_extracted.head(5))
return ex_extracted
def load_data(im_transformed):
print(im_transformed.shape)
current_time = now.strftime("%Y-%M-%d %H:%M:%S")
#save file in subfolder /data
im_transformed.to_csv('./data/311calls_'+ current_time +'_.csv')
extracted = extract_from_api()
transformed = transform_data(extracted)
load_data(transformed)