## Description:

My name is Jonathan and Data Wolf is my personal blog about full-stack web development, applied machine learning and music. # Data Wolf: Open Source Data Science

## Data Science Flashcards! | BETA

by Jonathan | January 19th, 2018

## Getting Started:

You have a few options when it comes to gettings answers.

### Option 1

You can use the QR code on the card, this will take you the web link with the card answer.

### Option 2

Jupyter notebooks are often used by Data Scientists and now you can use them to find the answers to the flashcards below!

### Flashcard 1 | Hello Smooth Operators!

``````print(35+16) # <-- Or just type 35+16 (NOTE: if you press enter, it will run.)
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)
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
'e'
``````

### Flashcard 8 | Replace list items

``````x = ["a", "b", "c", "d"]
x = "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)
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
print(d)

``````
``````  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
print(d)

``````
``````        english  population
country
us         True         323
japan     False         127
peru      Fasle         131
chile     False          17
``````

### Flashcard 34 | Pandas Brackets

``````import pandas as pd
print(lang['country'])
``````
``````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.index = [row_labels]

print(lang.loc['JAP'])

``````
``````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

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) + " is " + str(i))
...
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
``````