Here is what I intend to cover today:
At the end of this process, I would like for each of you to be able to create an Jupyter Notebook locally on your computer, and then be able to allow anyone else to see it using the online Jupyter Notebook Viewer (https://nbviewer.jupyter.org/).
This very same file we have on the screen now will make that journey.
Things you'll need to do ahead of time:
Some references that will be very helpful to ensure you understand what we are doing and how it all works:
OK. Let's get you started.
This file you are currently viewing is part of the course's git repository, which you can find here:
http://github.com/marioberges/F16-12-752/
Since it is in a public repository, you should be able to clone that repository into your computer and edit each file locally. For that, you could either clone it using the command line interface to git, or a graphical user interface (whichever you installed on your computer if you chose to install git). From the command line, for instance, you would issue this command to clone it:
git clone http://github.com/marioberges/F16-12-752.git
Make sure that you can clone the repository into your computer by issuing that command.
If you are successful, you will be able to see a new folder called F16-12-752
inside the folder where you issued the command. A copy of this Jupyter Notebook file should be in there as well, and you can view it by opening an IPython Notebook Server as follows:
jupyter notebook
Just make sure you issue this last command on the corresponding folder.
The steps we followed above were for cloning the course's official repository. However, you will want to repeat these steps for any other repository you may be interested in working with, especially the ones that you end up creating under your Github account. Thus, let's practice importing one of your repositories.
Follow these steps:
git clone http://github.com/yourusername/yourrepository.git
yourusername
and yourrepository
with the right information)Now it's time for you to practice some of your recently learned git skills.
Create a new Jupyter notebook, making sure to place it inside the folder of the repository you just cloned.
Add a couple of Python commands to it, or some comments, and save it.
Now go back to the terminal and add, commit and push the changes to your repository:
git add yourfile.ipynb
git commit -m "Made my first commit"
git push origin master
If this worked, you should be able to see the file added to your repository by simply pointing your browser to:
http://github.com/yourusername/yourrepository
Because Jupyter can be used to issue commands to a shell, directly, you can avoid having to switch to a terminal screen if you want to. This means we could have performed all of the above git manipulation directly from this notebook. The trick is to create a Code cell (the default type of cells) in the Jupyter notebook and then issuing the commands preceded by a !
sign, as follows:
In [1]:
!git status
Try running the above cell and see what you get.
In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [3]:
!file -I data/surveyresults.csv
In [4]:
!iconv -f utf-16le -t utf-8 < data/surveyresults.csv > data/surveyresults_fixed.csv
In [5]:
!file -I data/surveyresults_fixed.csv
In [6]:
with open('data/surveyresults_fixed.csv') as f:
contents = f.readlines()
In [7]:
len(contents)
Out[7]:
In [8]:
for i in range(len(contents)):
print(contents[i][-15:])
In [9]:
a = contents
out = []
for l in a:
d = l.split(' </ul>')[1]
nums = d.split('"')[2]
if len(nums) > 0:
n = nums.split(',')
try:
out.append([int(x) for x in n])
except Exception as e:
print('couldnt parse:', n)
#borda count
b_score = {}
for vote in out:
for i,paper in enumerate(vote):
if not paper in b_score:
b_score[paper] = 0
b_score[paper] += 5 - i
#sorting by boarda score
scores = [(paper, b_score[paper]) for paper in b_score]
scores.sort(key= lambda x: x[1], reverse=True)
#print the top 5 papers
for paper, b_score in scores[:5]:
print('Paper: #',paper, ' Borda score:', b_score)
In [ ]: