qmb3302 midterm

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/344

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

345 Terms

1
New cards

Which of the following operators represent proper means of comparison? Select all that apply.

!=

2
New cards

==

3
New cards

>

4
New cards

<

5
New cards

=

6
New cards

<=

7
New cards

Suppose you wanted to drive down to Tampa to watch the Rays play baseball, but you would only go if the cheapest ticket cost less than 20 dollars. If so, then your function would output "Take me out to the ballgame!" Tickets cost 26 dollars. Which function best illustrates this statement?

Ticket = 26

8
New cards

if ticket < 20

9
New cards

print ("Take me out to the ball game!")

10
New cards

Assuming this is a complete code chunk, and we expect to see output printed after running this, why is the below code incorrect? (chose the best answer, it may not be a great answer!)

11
New cards

If tom_brady == the goat:

12
New cards

print("The Buccs just won another Super Bowl")

The variables are not defined

13
New cards

What type of error will you receive of you forget to indent your nested if statement?

IndentationError

14
New cards

What is the purpose of an else statement? Choose the best answer.

It serves as a catchall function if if statement conditions are not met

15
New cards

How Many outputs will the following code have?

16
New cards

Mosquito = 1

17
New cards

While mosquito > 0:

18
New cards

print (mosquito)

19
New cards

mosquito = mosquito + 1

20
New cards

print(mosquito)

There are an infinite number of mosquitos

21
New cards

A While Loop is most closely related to which other type of function or statement (Choose the best answer)

"For" Loop

22
New cards

Within a "for" loop which line of code would you increase the number within a variable?

NONE {See which one}

23
New cards

Identify the parts of a for loop below:

24
New cards

for Iteration variable

25
New cards

in Iterables

26
New cards

:

27
New cards

Statement

(A) iteration Variable

28
New cards

(B) Iterables

29
New cards

(C) Statement

30
New cards

University of Florida President Kent Fuchs wanted to define a function to count the student enrollment of the top three colleges: Liberal Arts, Engineering, and Business. What two parts are MISSING in his code? His code looks like this:

31
New cards

MISSING collegecount(liberalarts, engineering, business):

32
New cards

enrollment = liberal_arts + engineering + business

33
New cards

MISSING enrollment

34
New cards

Note that the function doesn't do anything yet… there are no values for the 3 variables.

Def and return

35
New cards

Variable

A name, letter, or number that we assign VALUE , we assign using "="

36
New cards

Strings

Terms such as "Hello" or "Sorry that didnt work"

37
New cards

Tuples

Lists that you CANT change,

38
New cards

String Methods

'' '' = join puts spaces between terms/elements

39
New cards

"::" = Separated with colon's

40
New cards

"" = Separated by nothing

41
New cards

Dictionaries

A dictionary is a special object type in Python that does not rely on it's sequence or order. Dictionaries allow you to store information in an orderly way by creating a key-value pair.

42
New cards

So you'll recall that lists are created with a square bracket [ ], and Tuples are created with ( ). Dictionaries are created with a curly bracket { }

43
New cards

If

if statements allow you to create a branch in your code. "if this thing is true do x, otherwise do z". They can get kind of complicated, but at the most basic a branch/split is all they are doing.

44
New cards

Else If

Can evaluate more than 1 thing

45
New cards

Imagine we have a dataframe, df. What would be the purpose for running code like the below? (why would we run it?)

46
New cards

df.loc[1]

To look for, retrieve a value from df

47
New cards

Imagine we have a pandas dataframe we have named 'df'.

48
New cards

The dataframe consists of 2 columns.

49
New cards

"col1" is 30 values long, and is a random mix of the letters 'a', 'b', and 'c'.

50
New cards

"num1" is also 30 values long, and is a random set of numerical data (all integers).

51
New cards

Which of the following would give you the mean of the numerical (num1) column, grouped by the values from column "col1"?

df.groupby('col1').mean()

52
New cards

What is the shape of the following numPy array?

53
New cards

np.random.seed(1955)x = np.random.randn(2, 2, 2, 2)print(x.shape)x#Hint: I have not loaded the necessary package here…but you should

(2, 2, 2, 2)

54
New cards

What is the output of the following code?

55
New cards

import numpy as nplist1 = [5, 5, 5]list2 = [10, 10, 10]nplist1 = np.array(list1)nplist2 = np.array(list2)nplist1/nplist2

array([0.5, 0.5, 0.5])

56
New cards

numPy allows us to do more complicated math on lists and other data structures, and is used in most of the more advanced modules we will use (such as pandas)

True

57
New cards

pandas can be imported as

58
New cards

import pandas as pd

True

59
New cards

Usually a programmer will use conventional names when importing packages. But it is not strictly necessary.

60
New cards

numpy for example can be imported as:

61
New cards

import numpy as humpty_dumpty

True

62
New cards

pandas allows us to use multiple different data types (like objects and numbers) in a single table.

true

63
New cards

for pandas to work, data must be formatted as lists before it is imported.

False

64
New cards

When importing data from a local drive, the relative path was defined as the path FROM where your code in your current working directory is, TO where your data is

True

65
New cards

Look at the below code carefully. It is not at all uncommon to see errors of omission in code chunks like this.

66
New cards

How can you fix the below so that it produces the output 'array([50, 50, 100])'

67
New cards

import numpy as nplist1 = [5,5,5]

68
New cards

list2 = [10,10,20]

69
New cards

np_list1 = np.array(list1)

70
New cards

np_list2 = np.array(list2)

71
New cards

nplist1 isand np_list2

change "nplist1 isand nplist2" to "nplist1*np_list2"

72
New cards

pandas has functionality to work with complicated dates

True

73
New cards

What would be returned by the following code? Assume this is the only code in the workbook, nothing else is loaded or present.

74
New cards

import pandas as pd

75
New cards

today = datetime.datetime.now()

76
New cards

print(now)

an error

77
New cards

Imagine you have a dataframe, called 'tickets', with 4 columns: ('name', 'address', 'parkingspot', 'numberof_tickets')

78
New cards

If you wanted to subset out 2 columns, what code could you use (choose all that apply)

79
New cards
80
New cards

(By subsets, I mean show just 2 of the 4 columns, not the entire dataframe)

tickets.loc[:,['name', 'numberoftickets']]

81
New cards

Datasets to be joined generally need something in common, like a customer ID. The relationship does not need to be 1 to 1. (eg. Customer ID 75883 may occur once in the first dataset, and many times in the second dataset).

true

82
New cards

Pandas can be used to join two data frames together.

true

83
New cards

What is the mean of the column "A" in this DataFrame generated below? (choose the closest value)

84
New cards

(you may need to import additional packages to run the below code!)

85
New cards

import numpy as np

86
New cards

rng = np.random.default_rng(768561456982365)

87
New cards

create a dataframe using those random values!

88
New cards

df = pd.DataFrame(rng.integers(0,100,size=(15, 4)), columns=list('ABCD'))

import numpy as np

89
New cards

rng = np.random.default_rng(768561456982365)

90
New cards

create a dataframe using those random values!

91
New cards

df = pd.DataFrame(rng.integers(0,100,size=(15, 4)), columns=list('ABCD'))

92
New cards

np.mean(df["A"])

93
New cards
94
New cards

out: 60.93

95
New cards

What is the purpose of np.array in the below code?

96
New cards

a = [6.1, 5.8, 5.97, 5.43, 7.34, 8.67, 6.55, 3.66, 2.31, 6.84

97
New cards

]b = [2.5, 3.19, 2.26, 3.17, 8.17, 2.76, 5.22, 9.82, 3.95, 8.38]

98
New cards

np_a = np.array(a)

99
New cards

np_b = np.array(b)

Convert the lists 'a' and 'b' to a NumPy array

100
New cards

Imagine we create a pandas series using the below code. What is one simple way to retrieve the value 0.5 from the series?