Browse Source

Pandas

pull/69/head
Jure Šorn 4 years ago
parent
commit
c074e81e63
2 changed files with 8 additions and 4 deletions
  1. 6
      README.md
  2. 6
      index.html

6
README.md

@ -3382,7 +3382,9 @@ import plotly.graph_objects as go
import datetime
def main():
display_data(wrangle_data(*scrape_data()))
data = scrape_data()
df = wrangle_data(*data)
display_data(df)
def scrape_data():
def scrape_yahoo(id_):
@ -3400,8 +3402,8 @@ def scrape_data():
def wrangle_data(covid, dow, gold, bitcoin):
df = pd.concat([dow, gold, bitcoin], axis=1)
df = df.sort_index().interpolate()
df = df.loc['2020-02-23':].iloc[:-2]
df = df.rolling(10, min_periods=1, center=True).mean()
df = df.loc['2020-02-23':].iloc[:-2]
df = df / df.iloc[0] * 100
return pd.concat([covid, df], axis=1, join='inner')

6
index.html

@ -2866,7 +2866,9 @@ plotly.express.line(df, x=<span class="hljs-string">'Date'</span>, y=<span class
<span class="hljs-keyword">import</span> datetime
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span>
display_data(wrangle_data(*scrape_data()))
data = scrape_data()
df = wrangle_data(*data)
display_data(df)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">scrape_data</span><span class="hljs-params">()</span>:</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">scrape_yahoo</span><span class="hljs-params">(id_)</span>:</span>
@ -2884,8 +2886,8 @@ plotly.express.line(df, x=<span class="hljs-string">'Date'</span>, y=<span class
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">wrangle_data</span><span class="hljs-params">(covid, dow, gold, bitcoin)</span>:</span>
df = pd.concat([dow, gold, bitcoin], axis=<span class="hljs-number">1</span>)
df = df.sort_index().interpolate()
df = df.loc[<span class="hljs-string">'2020-02-23'</span>:].iloc[:<span class="hljs-number">-2</span>]
df = df.rolling(<span class="hljs-number">10</span>, min_periods=<span class="hljs-number">1</span>, center=<span class="hljs-keyword">True</span>).mean()
df = df.loc[<span class="hljs-string">'2020-02-23'</span>:].iloc[:<span class="hljs-number">-2</span>]
df = df / df.iloc[<span class="hljs-number">0</span>] * <span class="hljs-number">100</span>
<span class="hljs-keyword">return</span> pd.concat([covid, df], axis=<span class="hljs-number">1</span>, join=<span class="hljs-string">'inner'</span>)

Loading…
Cancel
Save