Path: blob/master/lessons/lesson_01/code/solution-code/Code_1.ipynb
1904 views
Kernel: Python 3
Check to see if you're ready to go on Thursday!
Run each block of code
Check for errors
When you think you're error free, flag down a teaching team member to confirm!
In [1]:
Out[1]:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-7fe2d780de59> in <module>()
1 ###This is what an error looks like
----> 2 print(a)
NameError: name 'a' is not defined
Objectives
Get comfortable with IPython Notebook
How to start IPython Notebook
How to read data into pandas
How to do simple manipulations on pandas dataframes
Start a notebook:
For each class, we'll be using a set of common data science libraries and tools, like the IPython notebook. You can start an IPython notebook by running
Try it yourself!
Read and run the block of code below by:
Clicking on it and pressing the play button above or
Using a short cut- (help --> keyboard shortcuts)
In [2]:
First: Read in the data
Review Simple Commands
Practice downloading and reading into sample data
In [3]:
In [4]:
Out[4]:
<matplotlib.collections.PathCollection at 0x925de80>
Try this Example:
Graph the number of noise complaints each hour in New York
In [5]:
Out[5]:
C:\Users\ystrano\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py:3: FutureWarning: how in .resample() is deprecated
the new syntax is .resample(...)..apply(<func>)
This is separate from the ipykernel package so we can avoid doing imports until
<matplotlib.axes._subplots.AxesSubplot at 0x9428da0>
Second: Using IPython
Review Python Basics
Test your skills by answering the following questions:
Question 1. Divide 10 by 20 and set the result to a variable named "A"
In [6]:
Out[6]:
0.5
In [7]:
Out[7]:
0.5
Question 2. Create a function called division that will divide any two numbers and prints the result (with decimals).
Call your function. Confirm that the results are as expected.
In [8]:
Out[8]:
2.0
0.5
Question 3. Using .split() split my string into separate words
In [9]:
Out[9]:
['the', 'cow', 'jumped', 'over', 'the', 'moon']
Question 4. How many words are in my_string?
In [10]:
Out[10]:
6
Question 5. Use a list comprehension to find the length of each word
In [11]:
Out[11]:
[3, 3, 6, 4, 3, 4]
Question 6. Put the words back together in a variable called sentence using .join()
In [12]:
Out[12]:
the cow jumped over the moon
Bonus: Add a "||" between each word
In [13]:
Out[13]:
the||cow||jumped||over||the||moon