Browse Source

CSV, Plotly

pull/167/head
Jure Šorn 1 year ago
parent
commit
6eb148e26d
2 changed files with 6 additions and 4 deletions
  1. 5
      README.md
  2. 5
      index.html

5
README.md

@ -1832,6 +1832,7 @@ import csv
<writer>.writerows(<coll_of_coll>) # Appends multiple rows. <writer>.writerows(<coll_of_coll>) # Appends multiple rows.
``` ```
* **File must be opened with a `'newline=""'` argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!** * **File must be opened with a `'newline=""'` argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!**
* **Open existing file with `'mode="w"'` to overwrite it or `'mode="a"'` to append to it.**
### Parameters ### Parameters
* **`'dialect'` - Master parameter that sets the default values. String or a 'csv.Dialect' object.** * **`'dialect'` - Master parameter that sets the default values. String or a 'csv.Dialect' object.**
@ -3466,8 +3467,8 @@ def scrape_data():
return map(pd.Series.rename, out, ['Total Cases', 'Bitcoin', 'Gold', 'Dow Jones']) return map(pd.Series.rename, out, ['Total Cases', 'Bitcoin', 'Gold', 'Dow Jones'])
def wrangle_data(covid, bitcoin, gold, dow): def wrangle_data(covid, bitcoin, gold, dow):
df = pd.concat([bitcoin, gold, dow], axis=1) # Joins columns on dates.
df = df.sort_index().interpolate() # Sorts by date and interpolates NaN-s.
df = pd.concat([bitcoin, gold, dow], axis=1) # Creates table by joining columns on dates.
df = df.sort_index().interpolate() # Sorts table by date and interpolates NaN-s.
df = df.loc['2020-02-23':] # Discards rows before '2020-02-23'. df = df.loc['2020-02-23':] # Discards rows before '2020-02-23'.
df = (df / df.iloc[0]) * 100 # Calculates percentages relative to day 1. df = (df / df.iloc[0]) * 100 # Calculates percentages relative to day 1.
df = df.join(covid) # Adds column with covid cases. df = df.join(covid) # Adds column with covid cases.

5
index.html

@ -1526,6 +1526,7 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-
<ul> <ul>
<li><strong>File must be opened with a <code class="python hljs"><span class="hljs-string">'newline=""'</span></code> argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!</strong></li> <li><strong>File must be opened with a <code class="python hljs"><span class="hljs-string">'newline=""'</span></code> argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!</strong></li>
<li><strong>Open existing file with <code class="python hljs"><span class="hljs-string">'mode="w"'</span></code> to overwrite it or <code class="python hljs"><span class="hljs-string">'mode="a"'</span></code> to append to it.</strong></li>
</ul> </ul>
<div><h3 id="parameters">Parameters</h3><ul> <div><h3 id="parameters">Parameters</h3><ul>
<li><strong><code class="python hljs"><span class="hljs-string">'dialect'</span></code> - Master parameter that sets the default values. String or a 'csv.Dialect' object.</strong></li> <li><strong><code class="python hljs"><span class="hljs-string">'dialect'</span></code> - Master parameter that sets the default values. String or a 'csv.Dialect' object.</strong></li>
@ -2824,8 +2825,8 @@ ex.line(df, x=<span class="hljs-string">'Date'</span>, y=<span class="hljs-strin
<span class="hljs-keyword">return</span> map(pd.Series.rename, out, [<span class="hljs-string">'Total Cases'</span>, <span class="hljs-string">'Bitcoin'</span>, <span class="hljs-string">'Gold'</span>, <span class="hljs-string">'Dow Jones'</span>]) <span class="hljs-keyword">return</span> map(pd.Series.rename, out, [<span class="hljs-string">'Total Cases'</span>, <span class="hljs-string">'Bitcoin'</span>, <span class="hljs-string">'Gold'</span>, <span class="hljs-string">'Dow Jones'</span>])
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">wrangle_data</span><span class="hljs-params">(covid, bitcoin, gold, dow)</span>:</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">wrangle_data</span><span class="hljs-params">(covid, bitcoin, gold, dow)</span>:</span>
df = pd.concat([bitcoin, gold, dow], axis=<span class="hljs-number">1</span>) <span class="hljs-comment"># Joins columns on dates.</span>
df = df.sort_index().interpolate() <span class="hljs-comment"># Sorts by date and interpolates NaN-s.</span>
df = pd.concat([bitcoin, gold, dow], axis=<span class="hljs-number">1</span>) <span class="hljs-comment"># Creates table by joining columns on dates.</span>
df = df.sort_index().interpolate() <span class="hljs-comment"># Sorts table by date and interpolates NaN-s.</span>
df = df.loc[<span class="hljs-string">'2020-02-23'</span>:] <span class="hljs-comment"># Discards rows before '2020-02-23'.</span> df = df.loc[<span class="hljs-string">'2020-02-23'</span>:] <span class="hljs-comment"># Discards rows before '2020-02-23'.</span>
df = (df / df.iloc[<span class="hljs-number">0</span>]) * <span class="hljs-number">100</span> <span class="hljs-comment"># Calculates percentages relative to day 1.</span> df = (df / df.iloc[<span class="hljs-number">0</span>]) * <span class="hljs-number">100</span> <span class="hljs-comment"># Calculates percentages relative to day 1.</span>
df = df.join(covid) <span class="hljs-comment"># Adds column with covid cases.</span> df = df.join(covid) <span class="hljs-comment"># Adds column with covid cases.</span>

Loading…
Cancel
Save