In [ ]:
# an easy way to get the data necessary for following along with part 1 of the python intro
import numpy, pandas as pd
df = pd.read_csv('inflammation-01.csv',
header=None)
data = numpy.array(df)
1.0.1. Draw diagrams showing what variables refer to what values after each statement in the following program:
mass = 47.5
age = 122
mass = mass * 2.0
age = age - 20
1.0.2. What does the following program print out?
first, second = 'Grace', 'Hopper'
third, fourth = second, first
print third, fourth
1.0.3. "Adding" two strings produces their concatention: 'a' + 'b' is 'ab'. Write a function called fence that takes two parameters called original and wrapper and returns a new string that has the wrapper character at the beginning and end of the original:
print fence('name', '*')
*name*
1.0.4. If the variable s refers to a string, then s[0] is the string's first character and s[-1] is its last. Write a function called outer that returns a string made up of just the first and last characters of its input:
print outer('helium')
hm
1.0.5. We previously wrote functions called fence and outer. Draw a diagram showing how the call stack changes when we run the following:
print outer(fence('carbon', '+'))
In [ ]:
import pandas as pd
df = pd.read_csv('weather-numeric.csv')
In [ ]:
df.head()
In [ ]:
# use TAB to explore commands
In [ ]:
def predict(s):
if s['outlook'] == 'sunny':
return 'no'
else:
return 'yes'
In [ ]:
predict(df.loc[1]) # .loc[1] means "location = row 1"
In [ ]:
i = 0
predict(df.loc[i]) == df.play[i]
In [ ]:
for i in df.index:
# count how many predictions are correct
pass