Numpy, Panda, Vis. Flashcards
What is the primary purpose of the Pandas library in Python? (A) Web development (B) Data manipulation and analysis (C) Game development (D) Machine learning algorithms
B
Which of the following is NOT a valid way to create a list in Python? (A) list = [1, 2, 3, 4] (B) list = list((1, 2, 3, 4)) (C) list = {1, 2, 3, 4} (D) list = list(range(1, 5))
C
Which pandas method would you use to handle missing values in a DataFrame? (A) dropna() (B) fillna() (C) replacena() (D) removena()
B
What type of error does this code contain? result = 10 / 0 (A) SyntaxError (B) ZeroDivisionError (C) ValueError (D) TypeError
B
What does the following code return? list1 = [1, 2, 3]; list2 = list1; list2.append(4); print(list1) (A) [1, 2, 3] (B) [1, 2, 3, 4] (C) [4] (D) Error
B
Which pandas function would you use to read a CSV file? (A) pd.read_file() (B) pd.read_csv() (C) pd.open_csv() (D) pd.import_csv()
B
What error type would this code produce? my_dict = {‘a’: 1, ‘b’: 2}; print(my_dict[‘c’]) (A) SyntaxError (B) KeyError (C) IndexError (D) ValueError
B
What is the output of the following code? x = [1, 2, 3]; y = x; y = [4, 5, 6]; print(x) (A) [1, 2, 3] (B) [4, 5, 6] (C) [1, 2, 3, 4, 5, 6] (D) Error
A
Which pandas method creates a cross-tabulation table? (A) pd.tabulate() (B) pd.crosstab() (C) pd.cross() (D) pd.pivot()
B
What type of error does this code contain? def calculate_average(numbers): return sum(numbers)/len(numbers); print(calculate_average([])) (A) SyntaxError (B) ZeroDivisionError (C) ValueError (D) TypeError
B
What is the output of this code? a = 5; def func(): a = 10; print(a); func(); print(a) (A) 5, 5 (B) 10, 10 (C) 10, 5 (D) 5, 10
C
Which pandas function would you use to merge two DataFrames? (A) pd.merge() (B) pd.combine() (C) pd.join() (D) pd.concat()
A
What type of error does this code contain? import pndas as pd (A) SyntaxError (B) ImportError/ModuleNotFoundError (C) NameError (D) AttributeError
B
What is the output of the following code? print(list(range(0, 10, 2))) (A) [0, 2, 4, 6, 8, 10] (B) [0, 2, 4, 6, 8] (C) [2, 4, 6, 8] (D) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
B
Which pandas method would you use to group data by a specific column? (A) cluster() (B) groupby() (C) categorize() (D) segment()
B
What type of error does this code contain? x = 5; x.append(10) (A) SyntaxError (B) AttributeError (C) TypeError (D) ValueError
B
What is the output of this code? print(“Hello”*3) (A) HelloHelloHello (B) Hello Hello Hello (C) Hello3 (D) Error
A
Which pandas function would you use to get descriptive statistics of a DataFrame? (A) stats() (B) summary() (C) describe() (D) info()
C
What error would this code produce? def func(x, y=10, z): return x + y + z (A) No error (B) IndentationError (C) SyntaxError (D) TypeError
C
What is the output of this code? print([i for i in range(10) if i % 2 == 0]) (A) [0, 2, 4, 6, 8, 10] (B) [0, 2, 4, 6, 8] (C) [2, 4, 6, 8] (D) [1, 3, 5, 7, 9]
B
Which pandas method would you use to drop rows with missing values? (A) remove() (B) dropna() (C) clean() (D) filter()
B
What type of error does this code contain? num = int(“hello”) (A) SyntaxError (B) ValueError (C) TypeError (D) NameError
B
What is the output of this code? print(set([1, 2, 2, 3, 3, 3])) (A) [1, 2, 3] (B) {1, 2, 3} (C) {1, 2, 2, 3, 3, 3} (D) Error
B
Which pandas function would you use to select rows based on a condition? (A) select() (B) filter() (C) query() (D) where()
C
What error would this code produce? a = [1, 2, 3]; print(a[3]) (A) SyntaxError (B) IndexError (C) ValueError (D) KeyError
B
What is the output of this code? print(232) (A) 64 (B) 512 (C) 36 (D) 18
B
Which pandas method would you use to find duplicate values in a DataFrame? (A) duplicated() (B) find_duplicates() (C) get_duplicates() (D) dup()
A
What type of error does this code contain? with open(‘nonexistent_file.txt’, ‘r’) as f: data = f.read() (A) IOError (B) FileNotFoundError (C) OSError (D) ReadError
B
What is the output of this code? print(‘{0}, {1}, {0}’.format(‘hello’, ‘world’)) (A) 0, 1, 0 (B) hello, world, hello (C) hello, world, world (D) {0}, {1}, {0}
B
Which pandas method would you use to pivot a DataFrame? (A) rotate() (B) transform() (C) pivot() (D) transpose()
C
What error would this code produce? x = 1; print(x + “2”) (A) SyntaxError (B) TypeError (C) ValueError (D) No error, it prints “12”
B
What is the output of this code? print(bool([]), bool([0]), bool(0)) (A) True, True, False (B) False, True, False (C) False, False, False (D) True, False, False
B
Which pandas method would you use to rename columns in a DataFrame? (A) rename() (B) change_names() (C) alter() (D) modify()
A
What type of error does this code contain? def func(): return x; print(func()) (A) SyntaxError (B) NameError (C) ReferenceError (D) IndexError
B
What is the output of this code? print(“Python”[1:4]) (A) Pyt (B) yth (C) ytho (D) ython
B
In Python, indentation is optional and used only for code readability. (A) True (B) False
B
The break
statement exits only the innermost loop in nested loops. (A) True (B) False
A
Python dictionaries preserve the order of items as they were added (in Python 3.7+). (A) True (B) False
A
In Python, a variable can change its type during program execution. (A) True (B) False
A
The is
operator in Python checks if two objects have the same value. (A) True (B) False
B
The append()
method in Python modifies the original list and returns None. (A) True (B) False
A
In Python, a tuple is mutable. (A) True (B) False
B
The sort()
method in Python returns a new sorted list. (A) True (B) False
B
In Python, all functions return a value, even if not explicitly specified. (A) True (B) False
A
In Python, strings are immutable. (A) True (B) False
A
The global
keyword in Python allows modifying a global variable from within a function. (A) True (B) False
A
The \_\_init\_\_
method in a Python class is called every time an instance of the class is created. (A) True (B) False
A
Lists and tuples can be used as dictionary keys in Python. (A) True (B) False
B
In Python, a function can be passed as an argument to another function. (A) True (B) False
A