-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
62 lines (49 loc) · 2.29 KB
/
graph.py
File metadata and controls
62 lines (49 loc) · 2.29 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from fredapi import Fred
from pymongo import MongoClient
import pandas as pd
from config import fred_key
from functools import reduce
fred = Fred(api_key=fred_key)
import matplotlib.pyplot as plt
import plotly
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objs as go
from datetime import datetime
import datetime
# # time series plot for multiple columns
start_date = '2000-01-01'
end_date = '2000-12-31'
dates = pd.date_range(start_date, end_date, freq='MS')
fig = go.FigureWidget()
fig.update_layout(title="Rate Comparison")
graph_indexes = ["EMRATIO","UNEMPLOY", 'JTSJOL', 'JTS3000JOL', 'JTS6000JOL',
'JTS9000JOL', 'CUSR0000SAF112','JTU5100JOL','JTU5200JOL']
counter = 0
# graph_indexes = ["UNRATE","FEDFUNDS","CPIAUCSL","INTDSRUSM193N","T10YIEM","TB3MS", "CPALTT01USM657N",
# "CIVPART","PSAVERT","MPRIME", "LNS14000006"]
for d in graph_indexes:
# scrape API to dataframe
df = pd.DataFrame(fred.get_series(d, observation_start='2000-1-1'))
df.index.names = ['date']
newnames = ['Employment-Population Ratio', 'Unemployment Level',
'Total Non-Farm Jobs', 'Manufacturing Jobs',
'Education/Health Services Jobs',
'Government Jobs',
'Meat/Poultry/Fish/Eggs Consumer Price',
'Information Jobs', 'Finance/Insurance Jobs']
# convert dataframe to list
df_list = df.values.tolist()
# flatten list
df_list = [item for subl in df_list for item in subl]
# add index to graph
fig.add_scatter(x=dates, y= df_list, name = newnames[counter], selected=None)
#fig.add_scatter(x=dates, y= df_list, name = d, selected=None)
fig.layout.xaxis.tickvals = pd.date_range(start_date, end_date, freq='MS')
counter = counter + 1
## make the ticks bold
# fig.layout.xaxis.tickformat = '%Y'
# fig.layout.xaxis.tickvals = ['2000-01-01','2007-01-01', '2007-09-01', '2008-01-01', '2008-09-01', '2009-01-01', '2010-01-01', '2011-01-01', '2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01', '2016-01-01', '2022-03-09']
# fig.layout.xaxis.ticktext = ['2000','2007', 'Financial Crisis Starts', '2008', 'Financial Crisis Ends', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016','2022-03-09']
# dump graph to html
fig.write_html("Event_Impact.html")