Programming Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Name and ID are columns to be removed from a data frame, df1. Which of the following is the proper way to do it? .drop( columns = ​[Name, ID] ) .drop( columns = {'Name', 'ID'} ) .drop( columns = ​['ID', 'Name'] ) .drop( columns = ​['Name'; 'ID'] )

.drop( columns = ​['ID', 'Name'] )

For i in range (0, 3): print( i * 3)

0 3 6

Range (4) will give the range of numbers: 4 0, 1, 2, 3, 4 1, 2, 3, 4 0, 1, 2, 3

0, 1, 2, 3

Range (0, 5, 2) will give the range of numbers ___. 0, 2, 4 1, 3, 4 0, 1, 2, 3, 4 1, 3, 5

0, 2, 4

numbers = ​[43, 24, 375] for i in range ( ): print( numbers ​[i] ) Which of the following choices used as arguments for the range function, would ensure that the entire list is looped through? 2 0, 2 0, 2, 1 0, 3, 1

0, 3, 1

what should be added between the code arugula=df['pizza_ingredients'].str.contains('Arugula') print(len(arugula))

1) The contains function returns a true/false value for each row of the data frame and thus does not contain only the rows with pizzas that have arugula. 2) The following line of code should be inserted between the two lines. argula = df [ arugula ] Explanation: Since the print statement uses the arugula variable, that variable name must be overwritten with a data frame.

What are the range of numbers generated by range(1, 5, 2) 1,2,3,4,5 1,3 1,3,5 2,4

1,3

Total = 0 for i in range (0, 5): total = total + i print(total) output??

10

What is the output? number1 = 5 number1 = 10 #number1 = 2 print (1 + number1) 6 11 3 15

11

number1 = 5 number1 = 15 #number1 = 10 print (1 + number1) 6 11 16 error

16

number1 = "2.5" number2 = "40" print(number1 + number2)

2.540

How many partitions will result from the following? line = "A Whole New World of" partitions = line.partition(" ") 3 4 5 0

3

for i in range (31, 34): print (i, end = " ") What will be the output of the code above? 31 32 33 31 32 33 31 32 33 34 31 32 33 34

31 32 33

How many numbers would be generated by the following range? range (0, 5, 1)

5

for i in range(5, 18, 3): print( i, end = " ")

5 8 11 14 17

What would be the range of numbers generated by range (5, 0, -1)

5, 4, 3, 2, 1

for i in range (50, 60, 2): print (i, end = " ") What would the output of the code above be? 52 54 56 58 60 50 52 54 56 58 60 50 51 52 53 54 55 56 57 58 59 60 50 52 54 56 58

50 52 54 56 58

total = 0 for i in range (1, 4): total = total + i print(total) What is the output? Enter your answer a numeral, e.g. 0 or 1 instead of spelling out the word.

6

list_of_numbers = [ 34, 56, 67, 53, 24] print( list_of_numbers[ 2: ] ) Which numbers would be selected? 56, 67 67, 53, 24 34, 56 67, 53

67, 53, 24

Consider the following code: list1 = [43, 78, 43, 34] list2 = [34, 78, 89] set1 = set(list1) set2 = set(list2) set3 = {78, 908} joined_set = set1.union(set2) intersected_set=joined_set.intersection(set3) for each_number in intersected_set: print(each_number)

78

numbers = [1, 2, 3, 4, 5] total = 0 for i in range (0, len(numbers), 2 ) total = total + numbers[i] print(total) 10 9 6 15

9

What will be the output of the following lines of code? ssn = "982-23-2324" print(ssn.replace(" ", "")) 982232324 982-22-2224 982-33-3334 982-23-2324

982-23-2324

What will be the output of the following lines of code? ssn = "982-23-2324" print(ssn.replace(" ", "")) 982-23-2324 982-22-2224 982232324 982-33-3334

982-23-2324

Which of the following is the ideal candidate for using dictionaries? A series of scores for an uncertain number of students Data about one student Data about a number of students Series of logically related values that can be described with a name or a label

Data about one student Series of logically related values that can be described with a name or a label

A blank string is counted as a null value when reported by the info() method of a DataFrame. True False

False

person = {"name": "Fred", "id": "23423" } for each_item in person: print( person​[each_item] ) What values would get printed out? name Fred name id Fred 23423 id 23423

Fred 23423

df.loc[10, 'Name'] = 'John' df.loc[10, 'ID'] = 200 df = df['Name'].replace('John', 'Mike') print ( df.loc[10, 'ID' ] ) What is the output? 200 10 John ID N/A - Error

N/A - Error

title = "Netflix and Chill" print ( title​​[0:3] ) Net Netf etfl etf

Net NOT INCLUSIVE UPPERBOUND

for i in range (50, 10, 10): print (i, end = " ") What would the output of the code above be? No output 50 40 30 20 10 10 20 30 40 50 50 40 30 20

No output

df​[column].isna() will return you ____. DataFrame of Index numbers and Booleans DataFrame Series of 0 or 1 Series of Booleans

Series of Booleans

What is the output? number1 = 6 number2 = 11 print (Number1 + number2) 6 11 17 Something else / error

Something else / error

assume df has 10,000 rows the query is not working and returns 0 rows. why? dropped_prices = df.query("price == 0") dropped_prices.info() hint(dtype is object)

The data type for price column shows in the info is object. Within the query, the value of 0 does not have quotes and is therefore an integer literal. Comparing a string within a column (type object) with an integer will not result in any matches. Therefore, a total of 0 records are matches in the query and 0 records are returned.

adress purpose, parameters, return values, assignments, or any issues df['brand'].dropna() df.head()

This code invokes the dropna() function. The dropna() function does not require a parameter, and it drops all the rows with na values. This function is being invoked for the 'brand' column of df and thus only na values in the brand column are considered. This function call will not update the original data frame, df, and will return a copy of the updated data frame. Since that value is not stored in a new variable, the update data frame will be lost.

df = df['Name'].replace("abc", "A-B-C") Study the code above and explain what it would do. Explain each part of the code. If a part of it would not work, explain why it would not work. If there are logical or syntax errors, list them.

This line of code will replace occurrences of 'abc' within the 'Name' column with 'A-B-C'. The replace function will return only the 'Name' column. LOGICAL ERROR: the returned series (only one column) will overwrite the entire data frame, df, and there will be data loss.

A CSV consists of only one value, 50. When imported as a Data Frame, it would have rows and columns. True False

True

there is a data fram with 100 rows. the 'name' columns has 5 rows with the name 'Michael' would you the code return? df['name'].str.contains('Michael') a df with 100 rows a series with 100 rows a df with 5 rows a series with 5 rows

a series with 100 rows

A function call in Python needs parentheses: sometimes depending on whether the method has a fixed number of parameters sometimes depending on whether the method has return values always without exception sometimes depending on whether the method has a variable number of parameters

always without exception

a functional call in pyhton needs parentheses sometimes depending on fixed numbers Sometimes depending on whether a method has return values or not always without exception Sometimes depending on the method has a variable number

always without exception

cafe_list = ["c", "b"] cafe_list.append("a") cafe_list.append("d") cafe_list.append("c") cafe_list.remove("c") for each_cafe in cafe_list: print(each_cafe, end=" ")

b a d c

A TUPLE _____, whereas a LIST ____. cannot be modified , can be modified can be modified , cannot be modified

cannot be modified , can be modified

A set ____. Complete the statement by selecting the choice that is true. cannot have duplicate items can be used instead of a list as it provides all the same functionality can have multiple items which have the same value can have duplicate item

cannot have duplicate items

There is a dataframe, df, with the data above. Which of the following would correctly rename the instances of "Europe" to "EU" in df. df.replace("Europe", "EU", regex = True) df.replace("EUROPE", "EU", inplace= True) df = df.replace("Europe", "EU", regex = True) df = df.replace("EUROPE", "EU")

df = df.replace("Europe", "EU", regex = True)

Assume df is a data frame with a column named 'Salary'. The data frame, df, has 10,000 records in it with 500 rows with salary greater than $75,000. df = df.query(" `Salary` > 75000 ") After the code above is run, which of the following would be true? df will have 10,000 records and an uncertain number of rows of salary > 75k df will have 10,000 records and 500 rows of salary > 75k df will have 500 records and an uncertain number of rows of salary > 75k df will have 500 records and 500 rows of salary > 75k

df will have 500 records and 500 rows of salary > 75k

Which of the following would be the correct way of implementing the code so that columns are dropped in the df data frame and the original data frame is updated properly. df = df.drop(columns = "id", inplace = True) df2.drop (columns = "id", inplace = True) df.drop(columns = "id", inplace = True) df2 = df.drop(columns = "id")

df.drop(columns = "id", inplace = True)

Which of the following results in a series of True/False values? df.duplicated( ) df.unique() df.index df.query( )

df.duplicated( )

to find out all the row index numbers for a dataframe, df, use: df.indices df.index df.index() df.indexes

df.index

fix the query, trying to find all rows that have an order ID less than 100 df.query("Order ID <= '100' ")

df.query("`order id` < 100 ") # order id has a space in the column name # order id is numeric

Which is the correct way to calculate the mean of a column Quiz1? df[ Quiz1 ].mean df[ 'Quiz1' ].mean() df[ 'Quiz1' ].mean df( 'Quiz1' ).mean()

df[ 'Quiz1' ].mean()

which is the correct way to calculate the mean of a column "Quiz1" df['Quiz1'].mean() mean(df['Quiz1']) df('Quiz1').mean() df[{Quiz1}].mean()

df['Quiz1'].mean()

To see the full data in row indexes 18 to 25 of a data frame, df, you can use ____. df[18, 25] df.loc[18:25] df[18:25] df.index[18:25]

df[18:25]

How would we delete all the rows with invalid cell data? dropna deletenull dropnull deletena

dropna

Which of the following can be used to delete a row with an NA value? fillna() removena() deletena() dropna()

dropna()

To link multiple if conditions, use an ___ else else if elif Elif

elif

number1 = 5 number2 = 10 print (Number1 + number2) What is printed out? 0 15 10 error

error

number = 5i f number > 5 : print ("a") else:print("b") What is the output of the code above? a b no output error

error (no indentations)

The function dropna() will drop ___: every row where every column value has an na value. every row where any column value has an na value. every column that has an na value. specified row indexes where any column value has an na value.

every row where any column value has an na value.

How do we change all na values to a specific value? change replace fillna changena

fillna

Which of the following can be used to replace an NA value with a zero? fillzero() fillna() putzero() dropna()

fillna()

A(n) _____ name is followed by parentheses in Python. attribute index variable function

function

Load a python library using the keyword ____. import add module lib

import

Which of the following would cause an original DataFrame to be modified? original = True original = False inplace = True inplace = False

inplace = True

If Julio wants to find out if two TUPLES have duplicate items, he could use the ___ function. join function from LISTS intersection function from SETS intersection function from TUPLES duplicates function from TUPLES

intersection function from SETS

Be default, if to_numeric() function encounters a string, it ____. forces a conversion to NA is unable to do the conversion and the function crashes with an error coerces a conversion to NA is unable to do the conversion, and changes the value to a None

is unable to do the conversion and the function crashes with an error

a method or function can have multiple return values true false kind of - it cant return them, but on variable can have multiple values within it

kind of - it cant return them, but on variable can have multiple values within it

Create an empty list named list_of_cars. Add "Mazda", "Toyota" and "Honda" as elements of the list.Using a loop, print out all the elements of the list.

list_of_cars = [] list_of_cars.append("Mazda") list_of_cars.append("Toyota") list_of_cars.append("Honda") for each_car in list_of_cars: print(each_car)

If you want to be able to have items in a data structure ordered by index numbers and be able to remove some elements later on as well, you would choose ____. tuples lists dictionaries sets

lists

Which is the correct way to specify keyword arguments? method(1 : keyword, 2 : keyword) method(keyword: 1, keyword: 2) method(1, 2) method(arg1= 1, arg2 = 2)

method(arg1= 1, arg2 = 2)

which is the correct way to specify keyowrd arguments? method(1,2) method(keyword:1. keyword:2) method(1: keyword, 2:keyword) method(arg1=1, arg2=2)

method(arg1=1, arg2=2)

1) Write a query to find out which schools have a mid-career median salary higher than $75,000. Store this subset of data in a variable. 2) Calculate the average mid-career median salary from the subset of data you identified in Part 1 and store it in a variable. 3) Using a print statement, print out the average mid-career median salary. You must enclose the statement within a fully formed English sentence instead of merely printing the number out. Format the salary like a currency.

mid_median_salary_df = df['School Name'].query("`Mid-Career Median Salary` > 75000") average_mid_salary = mid_median_salary_df.mean() print(f"The average mid-career median salary is ${average_mid_salary:.2f}")

movie = "A New Hope"Which of the following would select "New" from the string above? movie[2:5] movie(2:4) movie{2:5) movie[2:4]

movie[2:5]

movie = "Lord of the Rings" How would we extract "Lord" from the string? movie​[:4] movie​[4:0] movie​[0:4] movie​[:5]

movie​[0:4] OR movie​[:4]

set1 = {32, 56, 78} set2 = {32, 56, 79, 32} The conjunction of set1 and set2 will have ____ elements. n/a - none of these answer choices are valid 2 n/a - there is no such function 4

n/a - there is no such function

Which of the following properly sets up a dictionary? name = dictionary (name, id) name = { name="Adam", id=2300 } name = ( 'name': 'Adam', 'id': 2300 ) name = { 'name': 'Adam', 'id': '2300' }

name = { 'name': 'Adam', 'id': '2300' }

Which of the following would generate an error? numbers = ​[1, 2, 3] numbers.append(4) numbers = (1, 2, 3) numbers.append(4) numbers = ​[1, 2, 3] numbers.remove(3) numbers = (1, 2, 3) numbers.remove​[3]

numbers = (1, 2, 3) numbers.append(4) OR numbers = (1, 2, 3) numbers.remove​[3]

Which of the following creates a list? numbers = [1, 2, 3] numbers = {1, 2, 3} numbers = (1, 2, 3) numbers = "1, 2, 3"

numbers = [1, 2, 3]

Which of the following creates a set? numbers = "1, 2, 3" numbers = [1, 2, 3] numbers = {1, 2, 3} numbers = (1, 2, 3)

numbers = {1, 2, 3}

If df is a data frame with multiple columns, df['id'] will be expected to be a ____. one data frame one series of values list of index numbers multiple columns of values

one series of values

For the code below, how you would set the the city to "Pittsburgh"? person = { "name": "John", "city": "Chicago", } person{city} = "Pittsburgh" person[city] = "Pittsburgh" {person.city} = "Pittsburgh" person['city'] = "Pittsburgh"

person['city'] = "Pittsburgh"

phrase = "AZ AR AK CO IL WA PA" The ___ function call returns a total of 3 elements in Python. phrase.partition(" ") phrase.split("") phrase.split(" ") phrase.parts(" ")

phrase.partition(" ")

Using the following code, how will you print only the name? data = { 'name': 'Adam', 'id': '2300' } print ( data.name) print ( data​[name]) print ( data​['name']) print ( data!name)

print ( data​['name'])

Which of the following shows a nested function call? print ( name.title() ) name = name.title() print ( name ) print.nested()

print ( name.title() )

To get numbers4, 2, 0 use: range (4, 2, 0) range (5, 2, -1) range (4, -1, -2) range (4, 0, -2)

range (4, -1, -2)

If you were given a file which had data separated by semi-colons, i.e. a ';' character, you could load it in Pandas by using ____. open_file(type="sc", url) open_file(type="semicolon", url) read_csv(url, sep = ';') open_csv(url, sep=";")

read_csv(url, sep = ';')

To do a case-sensitive replace, use the ____ kwarg. regex_case regex case_sensitive casesensitive

regex

% is the ____ operator. division modularity remainder exponent

remainder

To remove an item from a list data structure, use ____. delete remove forget x

remove

For a file that was delimited by semi-colons, how would you specify that the values are delimited? delimiter = '\t' sep = '\t' delimiter = ';' sep = ';'

sep = ';'

A Series in Pandas likely contains ____. multiple rows and multiple columns single column and single row single row and multiple columns single column and multiple rows

single column and multiple rows

How do we get the character with index 4 from the string? star = "Maverick" star.len(4) star​[4] len(star, 4) star​[0:4]

star​[4]

state = "Pennsylvania" Which of the following will return the substring "Penn" in Python? state[:3] state[3:] state[4:] state[0:4]

state[0:4]

state = "Colorado" Which of the following will return the substring "Co" state[0:3] state[:2] state[1:2] state[:1]

state[:2]

state = "Massachussetts" Which of the following will return the substring "Mas" state[3:] state[0:4] state[:3] state[:4]

state[:3]

To type for the value of "99.32" is integer float real string

string

In Python to extract leading/trailing spaces, use ___. trim strip partition split

strip

What does the following code result in? name = Peter print ( name​[2:] ) eter ter e t

ter

df['100'] = 23 for the line of code above, we can tell that: there are at least 100 rows there are at least 100 columns there is a row with the name 100 there is a column with the name 100

there is a column with the name 100

How would we find out if an item is contained in a list? use an "if" with an "in" append use a "for" with an "in" use a "for", with an "if" and an "in"

use an "if" with an "in"

find out how many pizzas of size 'XXL' there might be in the data frame (column called pizza_size)

xxl_pizzas_df = df.query("pizza_size == 'XXL' ") xxl_count = len(xxl_pizzas_df) print(f"There were {xxl_count} XXL pizzas ordered")

A practical difference between strings and integers is that ___. you can do math on strings but not integers string are always alphabets whereas integers are always numerals. integers are always alphabets whereas strings are always numerals you can do math on integers but not strings

you can do math on integers but not strings

zip1 = "10001-0923" zip2 = " 90210" . Use string slicing to slice the strings seen above and print only the first 5 digits of the zipcode. The code you write must work with both the values of zip1 and zip2 shown above.

zip_code = zip1.strip() print(zip_code[:5])


Set pelajaran terkait

Real Estate Final, Chapter 5, Chapter 6, Chapter 7, Chapter 19, Chapter 21, Chapter 22, Chapter 17, Chapter 18, RE 350 - Chapter 1, RE 350 - Chapter 4, RE 350 - Chapter 9

View Set

CIS 2336 Internet Applications Development Final

View Set

Ch. 2: Reporting Intercorporate Investments and Consolidation of Wholly Owned Subsidiaries with No Differential

View Set

English B1 2015 CommuVoc 1 (Sentence), English B1 2016 CommuVoc 2.01-2.40 (Definition), English B1 2016 CommuVoc 2.01-2.40 (Translation)

View Set

Suggested questions from a prior class...

View Set

Our Eyes Were Watching God - Chapters 7-11 Questions

View Set

(Ch.23) Facility Design, Layout, and Organization

View Set

ATI Pharmacology Practice Test A (2019)

View Set