Description:
My name is Jonathan and Data Wolf is my personal blog about data science and machine learning. My first post, Data Science Flashcards was inspired by UC San Diego’s Data Science MicroMaster program and my favorite online bootcamps, DataCamp and DataQuest. They are freely available on Data Wolf’s Instagram.
Getting Started:
- Get Data Wolf Flashcards or visit Data Wolf Instagram.
- Try to solve them!
Getting Answers:
You have a few options when it comes to gettings answers.
Option 1
You can use Python by writing the function below also known as flashcard(0). You can use the command line:
- Write this Python 3 function:
def flashcard(my_num):
import requests
link = 'http://datawolf.us/p4ds/card'+ str(my_num) +'.txt'
f = requests.get(link)
print(f.text)
- Call this function by typing flashcard(1) in the shell as shown below. For single digit cards do not use 0, just 1-9.
flashcard(1)
>>> 35+16
51
>>> 25-16
9
>>> 3*5
15
>>> 10/2
5.0
>>> 2**7
128
>>> 18%7
4
flashcard(2)
>>> movie = 10
>>> popcorn = 25
>>> movie + popcorn
35
flashcard(3)
>>> a="This list"
>>> b=" demonstrates concatenation."
>>> my_list=a+b
>>> print(my_list)
This list demonstrates concatenation.
Option 2
Alternatively, you can use the QR code on the card.
Option 3
Jupyter notebooks are often used by Data Scientists. Take a look at the complete Data Wolf’s Jupyter Notebook like a Data Scientist or check out the modified version below:
Flashcard 0 | This is a function (flashcard)
def flashcard(my_num):
"""This function returns flashcard
answers by requesting a .txt file
from the DataWolf.us website. Just
type flashcard(1) from command line. """
import requests
link = 'http://datawolf.us/p4ds/card'+ str(my_num) +'.txt'
f = requests.get(link)
print(f.text)
Flashcard 1 | Math in Python is fun!
print(35+16) #Execute line by line like this: 35+16
print(25-16)
print(3*5)
print(10/2)
print(2**7)
print(18%7)
51
9
15
5.0
128
4
Flashcard 2 | Variables
movie = 10
popcorn = 25
(movie + popcorn) * 2
70
Flashcard 3 | Python lists
a="This list"
b=" demonstrates concatenation."
my_list=a+b
print(my_list)
This list demonstrates concatenation.
Flashcard 4 | For the love of cinema
movie = 10
popcorn = 75
print("Movie costs " + str(movie) +" and popcorn costs " + str(popcorn))
Movie costs 10 and popcorn costs 75
Flashcard 5 | Slicing lists
colors = ["blue", "red", "green"]
print(colors[1])
print(colors[-1])
print(colors[1:])
red
green
['red', 'green']
Flashcard 6 | Subsetting lists
colors = ["blue", "red", "green"]
old_colors = colors[0:2]
new_colors = colors[1:]
print(old_colors)
print(new_colors)
['blue', 'red']
['red', 'green']
Flashcard 7 | A lists of lists
flashcard(7)
>>> list_of_lists = [["a", "b"],["c"],["d","e"]]
>>> list_of_lists[2][1]
'e'
Flashcard 8 | Replace list items
x = ["a", "b", "c", "d"]
x[1] = "r"
x[2:] = "h","j"
print(x)
['a', 'r', 'h', 'j']
Flashcard 9 | Built-in functions
var1 = [1, 2, 3, 4]
var2 = True
var3 = int(var2)
print(len(var1))
print(var3)
4
1
Flashcard 10 | Baked-in help
#help(max) <-- uncomment to get help
#help(iter) <-- uncomment to get help
#help(type) <-- uncomment to get help
help(len)
Help on built-in function len in module builtins:
len(obj, /)
Return the number of items in a container.
Flashcard 11 | Sorting it all out
first=[1.0,3.0,5.0]
second=[2.0,4.0]
full = first + second
full_sorted = sorted(full, reverse=True)
print(full_sorted)
[5.0, 4.0, 3.0, 2.0, 1.0]
Flashcard 12 | String methods
doom = "videogame"
doom_up = doom.upper()
print(doom.count('o'))
1
Flashcard 13 | List methods
coins = [.01, .05, .10, .25, 1.00]
print(coins.index(.10))
print(coins.count(.01))
2
1
Flashcard 14 | Importing packages
from math import pi
print(pi)
3.141592653589793
Flashcard 15 | If this then that
doom = "game"
area = 100.0
if doom == "game":
print("Doom!")
Doom!
Flashcard 16 | Or else
doom = "videogame"
area = 14.0
if doom == "fruit":
print("an apple!")
else:
print("not sure")
not sure
Flashcard 17 | Just call me elif
doom = "videogame"
area = 14.0
if doom == "fruit":
print("an apple!")
elif doom == "videogame":
print("Game on!")
else:
print("not sure")
Game on!
Flashcard 18 | Numpy array(1)
import numpy as np
bills = [1, 5, 10, 20, 50, 100, 500]
np_bills = np.array(bills)
print(type(np_bills))
<class 'numpy.ndarray'>
Flashcard 19 | Numpy array(2)
import numpy as np
bills = [1, 5, 10, 20, 50, 100, 500]
np_bills = np.array(bills)
new_currency = np_bills * 26
print(new_currency)
[ 26 130 260 520 1300 2600 13000]
Flashcard 20 | Numpy array indexing
import numpy as np
print(bills[1])
print(np_bills[0:4])
5
[ 1 5 10 20]
Flashcard 21 | Numpy 2D arrays
bills = [[1, 5],[10, 20],[50, 100]]
np_bills = np.array(bills)
print(type(np_bills))
<class 'numpy.ndarray'>
Flashcard 22 | The shapes of lists
bills = [[1, 5],[10, 20],[50, 100]]
np_bills = np.array(bills)
print(np_bills.shape)
(3, 2)
Flashcard 23 | Lists, mean & median
bills = [1, 5, 10, 20, 50, 100]
import numpy as np
print(np.mean(np_bills))
print(np.median(np_bills))
31.0
15.0
Flashcard 24 | Lists, mean & median
x = [1,9,5,17]
y = [20,2,24,1]
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()
Flashcard 25 | Matplot scatterplot
x = [1,9,5,17]
y = [20,2,24,1]
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()
Flashcard 26 | Matplot histograms
x = [1,9,5,17,20,2,24,1]
import matplotlib.pyplot as plt
plt.hist(x)
plt.show()
Flashcard 27 | Python dictionary
countries = ['usa', 'russia', 'china']
capitals = ['washington', 'moscow', 'beijing']
ind_chi = countries.index('china')
print(capitals[ind_chi])
beijing
Flashcard 28 | Dictionary Earth
earth = {'usa:washington','russia:moscow','china:beijing'}
print(earth)
{'usa:washington', 'russia:moscow', 'china:beijing'}
Flashcard 29 | Earth keys
earth = {'usa:washington','russia:moscow','china:beijing'}
print(earth)
{'usa:washington', 'russia:moscow', 'china:beijing'}
Flashcard 30 | Manipulating Earth
earth = {'usa':'washingtown','russia':'moscow','china':'beijing'}
earth['usa'] = 'washington'
earth.pop('russia')
print(earth)
{'usa': 'washington', 'china': 'beijing'}
Flashcard 31 | Pandas dataframe
import pandas as pd
names = ["us","japan","peru","chile"]
eng = [True, False, False, False]
ppl = [809,988,101,77]
my_dict = {'country':names,'english':eng,'population':ppl}
lang = pd.DataFrame(my_dict)
print(lang)
country english population
0 us True 809
1 japan False 988
2 peru False 101
3 chile False 77
Flashcard 32 | Import to CSV
import pandas as pd
import csv
d = pd.read_csv('lang.csv')
print(d)
#Download dataset here: https://datawolf.us/datasets/lang.csv
#Once downloaded, navigate to that folder so python can read it.
country english population
0 us True 323
1 japan False 127
2 peru Fasle 131
3 chile False 17
Flashcard 33 | Return of the CSV
import pandas as pd
import csv
d = pd.read_csv('lang.csv', index_col=0)
print(d)
#Download dataset here: https://datawolf.us/datasets/lang.csv
#Once downloaded, navigate to that folder so python can read it.
english population
country
us True 323
japan False 127
peru Fasle 131
chile False 17
Flashcard 34 | Pandas Brackets
import pandas as pd
#lang = pd.read_csv('lang.csv')
print(lang['country'])
#Download dataset here: https://datawolf.us/datasets/lang.csv
#Once downloaded, navigate to that folder so python can read it.
0 us
1 japan
2 peru
3 chile
Name: country, dtype: object
Flashcard 35 | loc and iloc
import pandas as pd
row_labels = ['US', 'JAP', 'PE', 'CH']
lang = pd.read_csv('lang.csv')
lang.index = [row_labels]
print(lang.loc['JAP'])
#Download dataset here: https://datawolf.us/datasets/lang.csv
#Once downloaded, navigate to that folder so python can read it.
country japan
english False
population 127
Name: JAP, dtype: object
Flashcard 36 | Equality
True == False,2 == 5,'no' == 'no',False == 1
(False, False, True, False)
Flashcard 37 Import arrays(1)
import numpy as np
my_house = np.array([18.0, 20.0, 10.75, 9.50])
your_house = np.array([14.0, 24.0, 14.25, 9.0])
my_house >= 18
my_house < your_house
array([False, True, True, False], dtype=bool)
Flashcard 38 | Import arrays(2)
my_kitchen = 18.0
your_kitchen = 14.0
print(my_kitchen > 10 and my_kitchen < 18)
print(my_kitchen < 14 or my_kitchen > 17)
print(my_kitchen * 2 < your_kitchen * 3)
False
True
True
Flashcard 39 | Import CSV to series
import pandas as pd
row_labels = ['US', 'JAP', 'PE', 'CH']
lang = pd.read_csv('lang.csv', index_col = 0)
lang.index = [row_labels]
ppl = lang['population']
print(ppl)
US 323
JAP 127
PE 131
CH 17
Name: population, dtype: int64
Flashcard 40 | Compare Pandas series
import pandas as pd
lang = pd.read_csv('lang.csv')
row_labels = ['US', 'JAP', 'PE', 'CH']
lang.index = [row_labels]
ppl = lang['population']
big_ppl = ppl > 100
huge_ppl = lang[big_ppl]
print(huge_ppl)
country english population
US us True 323
JAP japan False 127
PE peru Fasle 131
Flashcard 41 | While if loops
music = 10
while music > 1:
print('jamming')
music = music -1
jamming
jamming
jamming
jamming
jamming
jamming
jamming
jamming
jamming
Flashcard 42 | While if loops
music = 10
while music != 0:
print('jamming')
if music > 0:
music = music -1
else:
if music < 1:
music = music +1
jamming
jamming
jamming
jamming
jamming
jamming
jamming
jamming
jamming
jamming
Flashcard 43 | For loops
some_numbers = [1.0,2.3,3.44,1.20,6.50]
for i in some_numbers:
print(i)
1.0
2.3
3.44
1.2
6.5
Flashcard 44 | Loops from scratch
flashcard(44)
>>> house = [["pool", 191.25],
... ["game room", 18.0],
... ["music room", 20.0],
... ["lounge", 19.50]]
>>> for i in house:
... print("The " + str(i[0]) + " is " + str(i[1]))
...
The pool is 191.25
The game room is 18.0
The music room is 20.0
The lounge is 19.5
Flashcard 45 | Loop over dictionary
world = {'spain':'madrid', 'france':'paris',
'germany':'bonn', 'norway':'oslo',
'italy':'rome', 'poland':'warsaw',
'australia':'vienna' }
for key, value in world.items():
print("the capital of " + str(key) + " is " + str(value))
the capital of spain is madrid
the capital of france is paris
the capital of germany is bonn
the capital of norway is oslo
the capital of italy is rome
the capital of poland is warsaw
the capital of australia is vienna
Flashcard 46 | Looping over Numpy
np_bills = np.array([20, 50, 10, 5])
np_coins = np.array([[ 25, 10],[ 1, 5]])
for i in np_bills:
print(i)
20
50
10
5
Flashcard 47 | Loop over dataframe
import pandas as pd
lang = pd.read_csv('lang.csv', index_col = 0)
for lab, row in lang.iterrows() :
print(lab)
print(row)
us
english True
population 323
Name: us, dtype: object
japan
english False
population 127
Name: japan, dtype: object
peru
english Fasle
population 131
Name: peru, dtype: object
chile
english False
population 17
Name: chile, dtype: object
That’s it.
Thank you for learning Data Science with Data Wolf!
This project is still in progress, check back in 2018.