







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








What if you multiple an integer with a string? please choose the outcome for Name2 of the following example :Name = "Zilong" Name2 = 3 *Name - ANSWER-ZilongZilongZilong What is the object/variable type of the following variable X? X = "1.0" - ANSWER-Float In python list indices start with number - ANSWER- Consider the following function: def sum_function(x=1, y=2): sum=x+y return(sum) What is a proper way to call this function? - ANSWER-sum_function() What is an argument in function? Is it mandatory? - ANSWER-Input, optional How to check the first 10 rows for a data set called "df" in Pandas. - ANSWER-df.head(10) How to quickly check the number of column and rows for a data set called "df" in Pandas. - ANSWER- df.shape How to obtain the summary statistic of all variable in dataset "df". - ANSWER-df.describe() How do you load a csv into a DataFrame in pandas? (import pandas as pd) - ANSWER- pd.read_csv('my.csv') How do you output the first 5 rows of a pandas DataFrame df? - ANSWER-df.print() How to select "CustomerType" column from hotel_df DataFrame? - ANSWER- hotel_df["CustomerType"] How to select booking orders with ADR (average daily price) greater than 100 for hotel_df DataFrame?
How to select all rows with "Children" > 2 from hotel_df set? - ANSWER- hotel_df[hotel_df["Children"]>2] Why does the argument "inplace = True" do for a given method? - ANSWER-To make sure the method modifies the dataframe To build a list, we enclose the elements in ___? ( ) [ ] { } None - ANSWER-[ ] A list can store: Single data type data Multiple data types Only text or character data - ANSWER-Multiple data types What does the following code print : a = "is" b = "nice" my_list = ["my", "list", a, b] print(my_list) ["my", "list", a, b] Error ['my', 'list', 'is', 'nice'] my_list - ANSWER-['my', 'list', 'is', 'nice'] Consider the list list1 = [[1, 2, 3], ["a", "b"], ["apple", 20, "x"]] Which of the following returns "apple"? List1[3][1] List1[3][0] List1[2][0] List1[2][1] - ANSWER-List1[2][0] Consider the list x = ['a', 'b', 'c', 'd'] What would be the result of the code below: print(x[-1]) 'd' Error 'b' 'a' - ANSWER-'d'
To round off a number x = 1.734 to 2 digits, we use ___: floor(x) round(x,2) round(x) ceil(x,2) - ANSWER-round(x,2) Which of the following statements is true? It is mandatory to have arguments to define a function A function can have no arguments A function can only have numeric arguments A function can have only string or character arguments We cannot have more than three arguments in a function - ANSWER-A function can have no arguments Which of the following statements is true? A function doesn't return a variable. A function returns a value, but the returned value cannot be assigned to a variable A function can only print values but cannot pass values to other variables We can assign the result of a function to a variable - ANSWER-We can assign the result of a function to a variable Which of the following statements is true? We cannot define our own functions in Python. Python doesn't have any built-in standard functions We can define functions in Python None of the choices - ANSWER-We can define functions in Python How to get the keys of the dictionary, continents? continents.k() continents.keys() continents.values() continents.items() - ANSWER-continents.keys() What are the ways you can manipulate a dictionary and create key-value pairs? The name of the dictionary is continents. continents['1']:"north america"' continents['1']='south america' continents.update({'2':'south america'} ) continents = continents.update({'2':'south america'}) - ANSWER-continents['1']='south america' continents.update({'2':'south america'} )
Correct syntax to convert the continents dictionary to a dataframe, df. df = pd.Data(continents) df = pd.DataFrame(continents) df = pd.from_dict(continents) df = pd.Series(continents) - ANSWER-df = pd.DataFrame(continents) How do we convert a CSV file to a dataframe? The csv file is one.csv. df = pd.read_csv("one.csv") df = pd.read("one.csv") df = pd.to_csv("one.csv") df = pd.from_csv("one.csv") - ANSWER-df = pd.read_csv("one.csv") How do we index the first 3 rows of a dataframe? The dataframeprovided is df. print(df[0:4]) print(df[0:3]) print(df[1:4]) print(df[:3]) - ANSWER-print(df[0:3]) print(df[:3]) You are given a csv file student_records.csv, dataframe student_records , Student name and marks are two columns in the dataframe. What is the right syntax to load the dataframe in pandas? pandas.read_csv('student_records.csv') pandas.read.csv('student_records.csv') pandas.readcsv('student_records.csv') pandas.csv('student_records.csv') - ANSWER-pandas.read_csv('student_records.csv') You are given a csv file student_records.csv, dataframe student_records , Student name and marks are two columns in the dataframe. How do we check the number of rows, their column names and types in the data frame?" student_records.inspect() student_records.inspect_data() student_records.info() student_records.describe() - ANSWER-student_records.info() You are given a csv file student_records.csv, dataframe student_records , Student name and marks are two columns in the dataframe. How can you find the number of rows in a dataframe? print(student_records.shape) print(student_records.shape[0]) print(student_records.rows)
A function name is always followed by ___? ( ) [ ] { } None of the choices - ANSWER-( ) Which of the following statements, when run after the below code, throws an ERROR? def function1(name1, name2): print(name1 + " " + name2) function1("Emily") function1("Emiyl","Jones") function1(name1="Emily",name2="Jones") function1(name2="Emily",name1="Jones") - ANSWER-function1("Emily") You are given a csv file employees.csv , dataframe employees, emp_no, emp_name, emp_salary are three columns in the dataframe. Which method calculates a few summary statistics for each column in the dataframe? employees.info() employees.describe() employees.head() employees.stats() - ANSWER-employees.describe() You are given a csv file employees.csv , dataframe employees, emp_no, emp_name, emp_salary are three columns in the dataframe. What is the right syntax to extract the column names of a dataframe? employees.columns employees["columns"] employees.cols() employees.columns() - ANSWER-employees.columns You are given a csv file employees.csv , dataframe employees, emp_no, emp_name, emp_salary are three columns in the dataframe. How do you sort values of the dataframe on the emp_salary column? employees.sort_values("emp_salary") employees.values_sort("emp_salary") employees.sort("emp_salary") employees.sortvalues("emp_salary") - ANSWER-employees.sort_values("emp_salary") You are given a csv file employees.csv , dataframe employees, emp_no, emp_name, emp_salary are three columns in the dataframe. How do you subset multiple columns in the dataframe?
employees.iloc["emp_no","emp_salary"] employees["emp_no","emp_salary"] employees[["emp_no","emp_salary"]] employees.loc["emp_no","emp_salary"] - ANSWER-employees[["emp_no","emp_salary"]] You are given a csv file employees.csv , dataframe employees, emp_no, emp_name, emp_salary are three columns in the dataframe. How to subset rows based on multiple conditions, such that both the conditions should meet? employees[(employees["emp_no"]>100) | (employees["emp_salary"]>1000000)] employees[(employees["emp_no"]>100) & (employees["emp_salary"]>1000000)] employees[(employees["emp_no"]>100) and (employees["emp_salary"]>1000000)] employees[(employees["emp_no"]>100) or (employees["emp_salary"]>1000000)] - ANSWER- employees[(employees["emp_no"]>100) & (employees["emp_salary"]>1000000)] You are given a csv file Sales.csv, dataframe Sales, Date, customer_id, item_name, no_of_items_bought and item_price are the columns in the dataframe. What is the right syntax to drop duplicates in pandas? ct! Sales.drop_duplicates(subset=["customer_id","Date"]) drop_duplicates(Sales[["customer_id","Date"]]) Sales.duplicates_drop(subset=["customer_id","Date"]) Sales.drop(subset=["customer_id","Date"]) - ANSWER- Sales.drop_duplicates(subset=["customer_id","Date"]) You are given a csv file Sales.csv, dataframe Sales, Date, customer_id, item_name, no_of_items_bought and item_price are the columns in the dataframe. How do you count the number of each item is seen in the dataframe? Sales["item_name"].values_count() Sales["item_name"].count_values() Sales["item_name"].value_counts() Sales["item_name"].count() - ANSWER-Sales["item_name"].value_counts() You are given a csv file Sales.csv, dataframe Sales, Date, customer_id, item_name, no_of_items_bought and item_price are the columns in the dataframe. Group the records by item_name and find the sum of no_of_items_bought. Sales.group_rows("item_name")["no_of_items_bought"].sum() Sales.group("item_name")["no_of_items_bought"].sum() Sales.groupby("item_name")["no_of_items_bought"].sum() Sales.group_by("item_name")["no_of_items_bought"].sum() - ANSWER-Sales.groupby("item_name") ["no_of_items_bought"].sum()
a) df[df["col1"] != 5] b) df[df["col1"] =! 5] c) df[df["col1"] == 5] d) df[df["col1"] = 5] - ANSWER-a) df[df["col1"] != 5] Which of the following Pandas method will report summary stats? a) head b) tail c) info d) describe - ANSWER-d) describe Suppose we have a dataframe df, which includes a column animal. I would like to count the number of times each animal appears in the column, e.g. Elephant: 8, Zebra: 7, etc. Which of the following commands can I use to do that? (more than may apply) a) df["animal"].value_counts() b) df.animal.value_counts() c) df.value_counts().animal() d) value_counts(df.animal) - ANSWER-a) df["animal"].value_counts() b) df.animal.value_counts() Assuming dataframe df is properly defined, what line of code would output the first 10 rows of data? a) df.head(11) b) df.head(9) c) df.head(10) d) df.head() - ANSWER-c) df.head(10) Which option will help us add a new element "d" to the list, L = ["a", "b", "c"] a) L.append("d) b) L[4] = "d" c) L[3] = "d" d) L = L + ["d"] - ANSWER-a) L.append("d) d) L = L + ["d"] Which of these will help us select the first two columns, c1 and c2, from the dataframe df? (if more than one apply, select all). a) df[c1,c2] b) df["c1", "c2"] c) df[["c1","c2"]] d) df("c1", "c2") - ANSWER-c) df[["c1","c2"]] What will be the output of List1[-2] if List1 is defined as below? List1 = ['Hello', 3, 'BADM', 211, 'Professor', 3.14] a) 3 b) 'Professor' c) 211 d) 'BADM' - ANSWER-b) 'Professor'
A list can hold multiple types of data, such as string, integer, and float. a) True b) False - ANSWER-a) True What would the following code output? var = [1, 2, [3] ,[5], [4,6,[7,8]]] print(len(var)) a) 8 b) 4 c) 5 d) 2 - ANSWER-c) 5 The following code to define a function to calculate area will throw an error. Select all the reasons that cause the error. def area_function{base=3, height=1}; area = 0.5 * base + height return(area) a) Line 2 and 3 are not indented b) Line one uses "{}" instead of "()" c) The formula for area in line 2 is wrong d) The function name has an underscore e) Line one ends with a semicolon and not a colon - ANSWER-a) Line 2 and 3 are not indented b) Line one uses "{}" instead of "()" e) Line one ends with a semicolon and not a colon How to convert the string "Illinois" to all lower case? a) "Illinois".lower[] b) Illinois.lower() c) "Illinois".lower d) "Illinois".lower() - ANSWER-d) "Illinois".lower() How would you print out the enrollment in business from this dictionary? Univ = {'business': {'name': 'gies', 'enrollment': 1500}, 'engineering': {'name': 'grainger','enrollment': 4500}} a) Univ[0][1] b) Univ[1][2] c) Univ[business][enrollment] d) Univ["business"]["enrollment"] - ANSWER-c) Univ[business][enrollment] Which of the following is an appropriate syntax for a key-value pair used in dictionaries? a) "Location"- "Urbana" b) "Location"; "Urbana" c) "Location", "Urbana" d) "Location": "Urbana" - ANSWER-d) "Location": "Urbana"
The difference between standard scaler and minimax scaler is that, using default settings, the values after minmax scaling will be between 0 and 1. a) True b) False - ANSWER-a) True On a standard scale, the outliers are generally the values that are less than -2 or greater than +2. a) True b) False - ANSWER-b) False