Week 5: Data Visualization Flashcards

(29 cards)

1
Q

Function calls

A

“calling” function = using the function
- takes in arguments
- outputs a return value

method = function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What to think about in function calls

A
  • what are the input arguments?
  • what does it do?
  • what is the output?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

round (34.34534, 2)

A

input: (34.34534, 2)
rounds 34.34534 to 2 decimal places
output: 34.47

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

abs (5-9)

A

input: -4
computes abs value
output: 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

len ([4, 5, 6])

A

input: [4, 5, 6]
calculates length
output: 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

print (‘hello’)

A

input: ‘hello’
prints input
output: None (doesn’t return)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

‘abc’.replace (‘b’, ‘d’)

A

input: ‘b’, ‘d’
calculates what ‘abc’ will be like if we replace all the ‘b’s with ‘d’s
output: ‘adc’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

def function_name (inputs)
blah blah…
return outputs

A

function_name: function header
inputs: parameter(s)
blah blah…: function body
outputs: returns

Ex:
def double (x)
return x*2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

‘ABcD5’.lower()

A

input: None
calculates lower case version
output: abcd5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

User-defined Function

A

You write a function yourself

  • chunk of code you can reuse
  • good practice in coding: modular and reusable
  • everything in function is indented (so python knows it’s a function)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Parameters

A

input variables in functions

  • arguments are what values you sent in for those variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Arguments

A

parameters by either position or keyword

  • the order of things in argument matter
  • my_function(arg1, arg2, …)
  • my_function(par1 = arg1, par2= arg 2) is same as my_function(par2 = arg2, par1= arg 1)
  • Ex: round(12.45, 1) different from round(1, 12.45)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Optional parameter

A

Followed by its default value

  • function definition starts with def my_function(par_default = arg_default)
  • call my_function() using default value
  • call my_function(par_default = arg) using specified value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Variable scope

A

portion of a program in which the name is valid

Consequences:
- parameters are local
- function call cannot prevede function header
- functions defined inside a function are local

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Local

A

anything defined inside a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Global

A

anything defined outside a function

16
Q

Conditional statemet

A

Stuff that is dependent on other things

17
Q

How to compare two things in python

A

a < b
- returns True if a<b (otherwise False)

a>b
- returns True/False

a==b
- returns True if a is equal to b

a!=b
- returns True if a not equal to b

a<=b
- returns True if a less than/equal to b

a>= b
- returns True if a greater than/equal to b

18
Q

if name.lower() == ‘messi’:
print (‘I guess your parents like soccer!’)

A

If your name is Messi –> will print comment

Not Messi –> nothing

To call on function:
- name = ‘Messi’
- name.lower() –> messi
- then use in function

19
Q

if len(surveyAnswer) == 0
print (‘No answer submitted’)
else:
print(surveyAnswer)

A

2 potential outcomes:
- print NA
- print the answer

20
Q

printing whether number is positive, negative, zero

A

if x<0:
print (‘N’)
elif x>0:
print(‘P’)
else:
print(‘Zero’)

21
Q

elif

A

else if

can add more if you want more outcomes

22
Q

Conditionals

A
  • always & only need to have 1 if statement
  • can have as many elif as you want
  • only 1 else statement (but don’t need it)
  • code runs if condition that is met is indented
  • can nest conditional statements
23
Q

Graph Basics

A
  • each plot needs title
  • x & y axis label
  • if multiple plots –> need a legend
  • make plots look nice w/ clear message
24
Box Plot
plotting 1 numerical variable - pth percentile (smallest value that has at least p% of data/below it) - quartile: 25th/75th percentile - medial: 50th percentile - IQR: 75th - 25th (middle 50% of data) - outlier: 1.5*IQR away from lower and upper quartiles - outliers drawn as stars - y-axis: numerical - no x-axis variables
25
Bar plot
plotting 1 variable - x-axis: categorical variable (can use discrete if not than many) - why not continuous: bc finite number of bars - y-axis: # of ppl, frequency etc. that chose the x-axis variable - why x & y if only 1 variable: y is number of times that color appears - can be in count or frequency (usually more interpretable - counts have more info but info not always useful
26
Histogram
1 variable - x-axis: numerical variables (bc have to calculate evenly spaces bins) - y-axis: counts/frequence of x-variable - can convert to bar plot by binning numerical variable (185-190) --> the (185, 190) bin
27
Bin size
Bin size matters (the size of each x-axis section)
28
Bar plot vs histogram
Bar: - categorical variables, discrete w/ few values - x-axis: categorical variable - each bar is different value for x Histogram: - continuous/discrete w/ many values - you pick number of bins you want - numerical variable gets "binned" into what looks like categorical variable Both: - y-axis: counts/ frequency - have bars