1/344
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which of the following operators represent proper means of comparison? Select all that apply.
!=
==
>
<
=
<=
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
if ticket < 20
print ("Take me out to the ball game!")
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!)
If tom_brady == the goat:
print("The Buccs just won another Super Bowl")
The variables are not defined
What type of error will you receive of you forget to indent your nested if statement?
IndentationError
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
How Many outputs will the following code have?
Mosquito = 1
While mosquito > 0:
print (mosquito)
mosquito = mosquito + 1
print(mosquito)
There are an infinite number of mosquitos
A While Loop is most closely related to which other type of function or statement (Choose the best answer)
"For" Loop
Within a "for" loop which line of code would you increase the number within a variable?
NONE {See which one}
Identify the parts of a for loop below:
for Iteration variable
in Iterables
:
Statement
(A) iteration Variable
(B) Iterables
(C) Statement
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:
MISSING collegecount(liberalarts, engineering, business):
enrollment = liberal_arts + engineering + business
MISSING enrollment
Note that the function doesn't do anything yet… there are no values for the 3 variables.
Def and return
Variable
A name, letter, or number that we assign VALUE , we assign using "="
Strings
Terms such as "Hello" or "Sorry that didnt work"
Tuples
Lists that you CANT change,
String Methods
'' '' = join puts spaces between terms/elements
"::" = Separated with colon's
"" = Separated by nothing
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.
So you'll recall that lists are created with a square bracket [ ], and Tuples are created with ( ). Dictionaries are created with a curly bracket { }
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.
Else If
Can evaluate more than 1 thing
Imagine we have a dataframe, df. What would be the purpose for running code like the below? (why would we run it?)
df.loc[1]
To look for, retrieve a value from df
Imagine we have a pandas dataframe we have named 'df'.
The dataframe consists of 2 columns.
"col1" is 30 values long, and is a random mix of the letters 'a', 'b', and 'c'.
"num1" is also 30 values long, and is a random set of numerical data (all integers).
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()
What is the shape of the following numPy array?
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)
What is the output of the following code?
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])
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
pandas can be imported as
import pandas as pd
True
Usually a programmer will use conventional names when importing packages. But it is not strictly necessary.
numpy for example can be imported as:
import numpy as humpty_dumpty
True
pandas allows us to use multiple different data types (like objects and numbers) in a single table.
true
for pandas to work, data must be formatted as lists before it is imported.
False
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
Look at the below code carefully. It is not at all uncommon to see errors of omission in code chunks like this.
How can you fix the below so that it produces the output 'array([50, 50, 100])'
import numpy as nplist1 = [5,5,5]
list2 = [10,10,20]
np_list1 = np.array(list1)
np_list2 = np.array(list2)
nplist1 isand np_list2
change "nplist1 isand nplist2" to "nplist1*np_list2"
pandas has functionality to work with complicated dates
True
What would be returned by the following code? Assume this is the only code in the workbook, nothing else is loaded or present.
import pandas as pd
today = datetime.datetime.now()
print(now)
an error
Imagine you have a dataframe, called 'tickets', with 4 columns: ('name', 'address', 'parkingspot', 'numberof_tickets')
If you wanted to subset out 2 columns, what code could you use (choose all that apply)
(By subsets, I mean show just 2 of the 4 columns, not the entire dataframe)
tickets.loc[:,['name', 'numberoftickets']]
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
Pandas can be used to join two data frames together.
true
What is the mean of the column "A" in this DataFrame generated below? (choose the closest value)
(you may need to import additional packages to run the below code!)
import numpy as np
rng = np.random.default_rng(768561456982365)
df = pd.DataFrame(rng.integers(0,100,size=(15, 4)), columns=list('ABCD'))
import numpy as np
rng = np.random.default_rng(768561456982365)
df = pd.DataFrame(rng.integers(0,100,size=(15, 4)), columns=list('ABCD'))
np.mean(df["A"])
out: 60.93
What is the purpose of np.array in the below code?
a = [6.1, 5.8, 5.97, 5.43, 7.34, 8.67, 6.55, 3.66, 2.31, 6.84
]b = [2.5, 3.19, 2.26, 3.17, 8.17, 2.76, 5.22, 9.82, 3.95, 8.38]
np_a = np.array(a)
np_b = np.array(b)
Convert the lists 'a' and 'b' to a NumPy array
Imagine we create a pandas series using the below code. What is one simple way to retrieve the value 0.5 from the series?