MCPcopy Index your code
hub / github.com/gto76/python-cheatsheet / wrangle_data

Function wrangle_data

web/update_plots.py:65–72  ·  view source on GitHub ↗
(covid, bitcoin, gold, dow)

Source from the content-addressed store, hash-verified

63 return map(pd.Series.rename, out, ['Total Cases', 'Bitcoin', 'Gold', 'Dow Jones'])
64
65 def wrangle_data(covid, bitcoin, gold, dow):
66 df = pd.concat([dow, gold, bitcoin], axis=1) # Joins columns on dates.
67 df = df.sort_index().interpolate() # Sorts by date and interpolates NaN-s.
68 yesterday = str(datetime.date.today() - datetime.timedelta(1))
69 df = df.loc['2020-02-23':yesterday] # Discards rows before '2020-02-23'.
70 df = round((df / df.iloc[0]) * 100, 2) # Calculates percentages relative to day 1
71 df = df.join(covid) # Adds column with covid cases.
72 return df.sort_values(df.index[-1], axis=1) # Sorts columns by last day's value.
73
74 def get_figure(df):
75 figure = go.Figure()

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected