Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mooc-rr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
6ba812c8b193df42eeb5de9ab7cfb35d
mooc-rr
Commits
845a7d14
Commit
845a7d14
authored
Mar 01, 2021
by
Miguel Felipe Silva Vasconcelos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix data format and finish exercise 4 modl 2
parent
2aa9afbd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
172 additions
and
28 deletions
+172
-28
data.csv
module2/exo4/data.csv
+29
-28
exercice_python_en.org
module2/exo4/exercice_python_en.org
+143
-0
simple_plot.png
module2/exo4/simple_plot.png
+0
-0
No files found.
module2/exo4/data.csv
View file @
845a7d14
01/02/21;14,6460667061335
2021-02-01;81.8199141820915
02/02/21;73,4672357276549
2021-02-02;45.6301076036676
03/02/21;44,2291538031916
2021-02-03;70.8706487695057
04/02/21;71,2903834045354
2021-02-04;5.97511114188613
05/02/21;68,4296251985456
2021-02-05;101.240121644893
06/02/21;63,7415933598351
2021-02-06;103.766043900565
07/02/21;12,1364474195974
2021-02-07;52.7243273488364
08/02/21;31,333298339329
2021-02-08;68.7124193984776
09/02/21;88,577182629412
2021-02-09;24.7699235269981
10/02/21;15,7374298284668
2021-02-10;118.519011934154
11/02/21;5,76424151805257
2021-02-11;72.366803329567
12/02/21;31,553181578714
2021-02-12;114.271575633934
13/02/21;2,8429101140257
2021-02-13;22.5772258584814
14/02/21;110,497435357668
2021-02-14;9.45448876418252
15/02/21;53,519193819704
2021-02-15;82.0417788209343
16/02/21;29,0710366548617
2021-02-16;113.367188637391
17/02/21;40,9590068501374
2021-02-17;69.0559521907761
18/02/21;108,901226649965
2021-02-18;23.3930819081197
19/02/21;89,8347247541098
2021-02-19;59.4513861286365
20/02/21;104,444763954637
2021-02-20;11.8306198096613
21/02/21;97,5087720203479
2021-02-21;38.6294301996271
22/02/21;91,3232707890844
2021-02-22;55.8762511123907
23/02/21;69,9688805761576
2021-02-23;69.6027586204646
24/02/21;18,6351020508254
2021-02-24;12.4944003236117
25/02/21;95,3568454045806
2021-02-25;115.595594989872
26/02/21;65,405377470914
2021-02-26;56.1790065946262
27/02/21;58,6261571771731
2021-02-27;64.3230348460476
28/02/21;56,492475928146
2021-02-28;4.86203636954475
module2/exo4/exercice_python_en.org
View file @
845a7d14
...
@@ -26,3 +26,146 @@ and minimum value, regarding the time spent on each day.
...
@@ -26,3 +26,146 @@ and minimum value, regarding the time spent on each day.
* Results of the experiments
* Results of the experiments
I'm using the [[https://pandas.pydata.org/][Pandas library]] to facilitate reading the date from the
CSV file and to learn a new tool :).
#+begin_src python :results value :session *python* :exports both #using value, prints the variable without showing the console output
import pandas as pd # using pandas to facilitate working with date and time
dataframe = pd.read_csv("data.csv", parse_dates=[0], delimiter = ';', header=None)
dataframe
#+end_src
#+RESULTS:
#+begin_example
0 1
0 2021-02-01 81.819914
1 2021-02-02 45.630108
2 2021-02-03 70.870649
3 2021-02-04 5.975111
4 2021-02-05 101.240122
5 2021-02-06 103.766044
6 2021-02-07 52.724327
7 2021-02-08 68.712419
8 2021-02-09 24.769924
9 2021-02-10 118.519012
10 2021-02-11 72.366803
11 2021-02-12 114.271576
12 2021-02-13 22.577226
13 2021-02-14 9.454489
14 2021-02-15 82.041779
15 2021-02-16 113.367189
16 2021-02-17 69.055952
17 2021-02-18 23.393082
18 2021-02-19 59.451386
19 2021-02-20 11.830620
20 2021-02-21 38.629430
21 2021-02-22 55.876251
22 2021-02-23 69.602759
23 2021-02-24 12.494400
24 2021-02-25 115.595595
25 2021-02-26 56.179007
26 2021-02-27 64.323035
27 2021-02-28 4.862036
#+end_example
* Calculating the average/mean
We can use pandas' [[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.mean.html][mean method]]
#+begin_src python :results output :session *python* :exports both #using output, prints only what is shown in the console
average = dataframe[1].mean()
print(average)
#+end_src
#+RESULTS:
: 59.621437271033706
* Calculating the standard deviation
We can use pandas' [[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.std.html][std method]]
#+begin_src python :results value :session *python* :exports both
std = dataframe[1].std()
std
#+end_src
#+RESULTS:
: 36.12909565271962
* Calculating the median
We can use pandas' [[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.median.html][median method]]
#+begin_src python :results value :session *python* :exports both
median = dataframe[1].median()
median
#+end_src
#+RESULTS:
: 61.88721048734205
* Finding the minimum value (time spent)
We can use pandas' [[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.min.html][min method]]
#+begin_src python :results value :session *python* :exports both
min = dataframe[1].min()
min
#+end_src
#+RESULTS:
: 4.86203636954475
* Finding the day with the minimum time spent studying
We can use pandas' [[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.idxmin.html][idxmin method]]
#+begin_src python :results output :session *python* :exports both
idmin = dataframe[1].idxmin()
idmin
print (dataframe[0][idmin] , dataframe[1][idmin] )
#+end_src
#+RESULTS:
: 2021-02-28 00:00:00 4.86203636954475
* Finding the maximum value (time spent)
We can use pandas' [[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.max.html][max method]]
#+begin_src python :results value :session *python* :exports both
max = dataframe[1].max()
max
#+end_src
#+RESULTS:
: 118.519011934154
* Finding the day with the maximum time spent studying
We can use pandas' [[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.idxmax.html][idxmax method]]
#+begin_src python :results output :session *python* :exports both
idmax = dataframe[1].idxmax()
idmax
print (dataframe[0][idmax],dataframe[1][idmax] )
#+end_src
#+RESULTS:
: 2021-02-10 00:00:00 118.519011934154
* Generating a graphic of the data:
#+begin_src python :results output file :session *python* :var matplot_lib_filename2="simple_plot.png" :exports both
from matplotlib import pyplot as plt
fig, ax = plt.subplots(figsize=(12, 12))
ax.bar(dataframe.index.values,
dataframe[1],
color='purple')
ax.set(xlabel="Date",
ylabel="Time Spent",
title="Daily Time spent studying for the MOOC on reproducible research - feb/2021")
plt.savefig(matplot_lib_filename2)
print(matplot_lib_filename2)
#+end_src
#+RESULTS:
[[file:simple_plot.png]]
module2/exo4/simple_plot.png
0 → 100644
View file @
845a7d14
27.6 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment