Emacs, this document can easily be exported to HTML, PDF, and Office
data_file = 'chickenpox_incidence.csv'
formats. For more information on org-mode, see
https://orgmode.org/guide/.
When you type the shortcut =C-c C-e h o=, this document will be
import datetime
exported as HTML. All the code in it will be re-executed, and the
from urllib.request import urlretrieve
results will be retrieved and included into the exported document. If
import os
you do not want to re-execute all code each time, you can delete the #
and the space before ~#+PROPERTY:~ in the header of this document.
Like we showed in the video, Python code is included as follows (and
if not os.path.exists(data_file):
is exxecuted by typing ~C-c C-c~):
urlretrieve(data_url, data_file)
#+begin_src python :results output :exports both
print(f'Data is retrieved at {datetime.datetime.utcnow()} UTC')
print("Hello world!")
#+END_SRC
#+end_src
#+RESULTS:
#+RESULTS:
: Hello world!
:
: Data is retrieved at 2020-09-16 22:07:31.650075 UTC
And now the same but in an Python session. With a session, Python's
Now we extract the interesting part of the data. from the format of the file The week is column 0, incidence is column 4. We took Monday as the first day of the week so '%W' code in python/pandas.
state, i.e. the values of all the variables, remains persistent from
one code block to the next. The code is still executed using ~C-c
C-c~.
#+begin_src python :results output :session :exports both
#+BEGIN_SRC python :session *python* :results outputs :export both
import numpy
import pandas as pd
x=numpy.linspace(-15,15)
data = pd.read_csv(data_file, skiprows=2, header=None)
print(x)
data = data.loc[:, [0, 2]].rename(columns={0:'Datetime', 2:'Incidence'})
Additionally, the data starts at the beginning of 1991 and ends at the beginning of the 2020. The monthly evolution is not clear from the long timeseries. Plotting a shorter version.