Python II Flashcards

1
Q

Primary data

A

Data collected by the individual doing the analysis

Experiments (labs)
Observations (surveys/sensors)
Simulations (theoretical models)
Scraping (webscraping)

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

Secondary data

A

Data collected by someone else and published for public use

Any primary data collected by someone else

Institutionalized data bands (census)

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

Random binomial

A

import numpy

print(numpy.random.binomial(n, p, size)

N = number of trials per experiment
P = probability of success per trial
Size = number of experiments

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

Slicing a string

A

string[first_index : last_index]

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

Mutability

A

Data types that can be changed are mutable

Data types that can’t be changed, like strings, are immutable

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

Escape character

A

Adding \ will escape the special character

“He said, \”blueberries are my favorite!\””

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

Boolean conditions with strings

A

print(“e” in “blueberry” and “e” in “carrot”)
Returns False

print(“e” in “blueberry” and not “e” in “carrot”)
Returns True

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

Splitting strings using escape sequences

A

‘\n’ will allow us to split by line breaks

‘\t’ will allow us to split by tabs

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

Replacing string method

A

string_name.replace(substring_being_replaced, new_substring)

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

Python dictionary

A

Unordered set of keys associated with values

Syntax to create
Menu = {“toast”: 6, “juice”: 5, “muffin”: 2}

Keys can be string or number

values can be any type of data

Syntax to add to a dictionary
dictionary[key] = value

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

Adding multiple keys to a dictionary at once

A

.update()

dictionary.update({“key1”:value1, “key2”:value2, …})

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

Dict comprehension

A

dictionary = {key:value for key,value in zip(list1, list2)

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

.get() for dictionaries

A

dictionary.get(‘key’, return value if none)

Will return value if the key exists

If the key does not exist it will return None

You can specify the return value if None with second argument

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

Remove an entry from dictionary using .pop()

A

dictionary.pop(key, return value if key does not exist)

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

Creating a dictionary with zip

A

Dictionary = {key:value for key, value in zip(list1,list2)

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