Data Analytics Test
What is the output of print(text[-1]) if text = 'Hello World!'?
!
To concatenate two strings, you would use the
+ operator
What is the output of the below program? a=[1,2,3,None,(),[],] print(len(a))
6
What is the output of the following code? print(type([1,2])
<type 'list'>
A module or library is
A set of functions and variables with a shared purpose stored in an independent file
What is an infinite loop?
A set of instructions that continue over and over again without stopping
The expression used to check if A is greater than B in Python is
A>B
Given X="ABCDEFGHIJKLMNOPQRSTUVWXYZ", X[0:20:2] is?
ACEGIKMOQS
A rectangular table of data object in pandas is called a
DataFrame
f=lambda x:x.max()-x.min()
Defines a function called f that calculated the range
Your "home directory" refers to the
Directory you start when you turn on your computer (or log in)
The suffix of a filename is called a
Extension
52cards is a valid variable name
False
Once defined, a string variable can be altered (i.e. s='Hello'; s[0]='K')
False
Slicing with pandas labels is the same as Python string or list slicing.
False
The "add" method adds elements to the end of a list.
False
The division (/) works the same in Python 2.x and Python 3.x
False
The container for data stored on a hard drive is called a
File
To organize files on a hard drive, you can use a
Folder
To import all the functions from the math module and remove the need for adding "math", you would use
From math import *
An expression
Is a combination of values, variables, and operators
Given X="ABCDEFGHIJKLMNOPQRSTUVWXYZ", X[10:0:-2] is?
JHFDB
Dictionaries differ from lists, sets, and tuples because
Lists, sets, and tuples use integers for index positions and dictionaries can use almost any Python type.
What does the zip function do?
Pairs two lists together and returns each pair of elements one at a time
The operator for multiplication is
Plain] *
Given X="ABCDEFGHIJKLMNOPQRSTUVWXYZ", X[16:7:-3] is?
QNK
A one-dimensional array-like object in pandas is called a
Series (needs to be capital)
The statement "something=1"
Sets the variable 'something' to (1)
What is wrong with the following code? If x>0: x=x+1 else: x=1 elif x<0: x=x-1
Syntax error (else case must be the last one)
What is wrong with the following code? If x>0 x=x+1
Syntax error(There is no colon at the end of an if statement)
What is wrong with the following code? def average(numbers): avg=0 for n in numbers: avg= avg + n avg= avg/len(numbers)
The code is correct, but it does not return a value
What is wrong with this code? For x in range(1,10,1): print(i)
The iteration variable needs to be the same(pick either x or i)
What is wrong with this code? For i in range(1,10,1): print(i)
The print statement needs to be indented
Why would you use the "try" and "except" reversed words?
To safeguard your program from unexpected runtime errors
If given a key, you can look up a value in a dictionary
True
The index of the last character of a string variable is -1
True
The bool Python data type represents...
True and False
Given X="ABCDEFGHIJKLMNOPQRSTUVWXYZ", X[21:17:-2] is?
VT
Which Python command can generate an infinite loop?
While
The int Python data type represents...
Whole counting numbers
The pages of an Excel workbook are called
Worksheets
What is the output of [1,2,3] +[4,5,6]?
[1,2,3,4,5,6]
Given X=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25], X[11:2:-3] is?
[12,9,6]
What is the output? tinylist=[123,'xyz'] print(tinylist * 2)
[123, 'xyz', 123, 'xyz']
Given X=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], X[13:3:-3] is?
[14,11,8,5]
Given X=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], X[13:18:3] is?
[14,17]
Given X=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25], X[13:14:2] is?
[14]
What is the following code an example of? If choice == 'a': print('Bad guess') elif choice == 'b': print('Good guess') elif choice == 'c': print('Close,but not correct')
a chained conditional
The worksheet that is currently (or most recently) viewed is called the
active sheet
To extract data from a web page, you can use
bats=pd.read_html("http://www.thebaseballcube.com/mlb/teams/stats.asp?Y=2021&T=2")
What is the following compares elements of both lists?
cmp(list1,list2)
To bring all the content of a file into a Python program, you would use a Python statement like
contents=fhandle.read()
To separate a Series into a set of buckets, you can use the method
cut()
Which of the following methods removes all of the key-value pairs from a dictionary called d?
d.clear()
Which of the following methods extracts all of the key-value pairs from a dictionary called d?
d.items()
Which of the following methods extracts all of the keys from a dictionary called d?
d.keys()
For reading dates in European format (dd-mm-yyyy), you would add the option to read_csv()
dayfirst=True
To delete rows 'a' and 'b' from a DataFrame called df, you can use
df.drop(['a','b'])
To delete columns 'a' and 'b' from a DataFrame called df, you can use
df.drop(['a','b'],axis="columns")
To select a row by label 'a' from a DataFrame df, you use
df.loc['a']
To select a column by label 'a' from a DataFrame df, you use
df.loc[:,'a']
To calculate the averages of a DataFrame df, you use
df.mean()
To sort a dataframe df by index, you use
df.sort_index()
To sort a dataframe df by its content, you use
df.sort_values()
To sort a dataframe df by columns 'a' and then by 'b', you use
df.sort_values(by=['a','b'])
To save a pandas data frame called df as "data.dat" comma separated value file, you can use
df.to_csv("data.dat")
To find the unique values in a column 'a' in dataframe df, you use
df["a"].unique()
To find the distribution of values of column 'a' in dataframe df, you use
df["a"].value_counts()
To compute a function f on a column 'a' in a DataFrame df, you use
df['a'].apply(f)
To access just columns 'a', 'b', 'c' from DataFrame df, you use
df[['a','b','c']]
To pick all the data from the DataFrame df with rows where values in column 'x' is greater than 10, you can use
df[df['x']>10]
To identify data that is replicated, you can use the method
duplicated()
The Python object for working with a file is called a
file handle
The convention for bringing pandas into a Python program is
import pandas as pd
To interact with a Web API, you can use
import requests
To interact with a SQLite database, you can use
import sqlite3
The function you can use to see if the dictionary contains a key is
in
Which of the following gets the length of the string?
len(string)
What is the following returns the lowest index in list that obj appears?
list.index(obj)
What is the following removes an object from a list?
list.remove(obj)
Which of the following converts a string to all lowercase?
lower()
Which of the following removes all leading whitespace in string?
lstrip()
To perform a calculation on every element of a Series, you can use
map()
What is the output of print(text[4]) if text = 'Hello World!'?
o
To find the current working directory using the os library module, you would use
os.getcwd()
For a Python program to prepare to put data into an existing file, you would use something like
outfile=open("newfile.txt", "a")
When you are finished with using a file handle called output in Python, you should call the function
output.close()
To put data into a file that has been opened as "output", you would use the statement like
output.write("This is data going into the file")
To change the index on a Series or DataFrame, you use
reindex()
To get the elements of a pandas Series called s, you can use
s.values
To pick a random number of rows of a dataframe without replacement, you can use the method
sample()
To copy a file, you would use the function
shutil.copy()
To copy a directory, you would use the function
shutil.copytree()
Which of the following flips the case of a string?
swapcase()
Which of the following convert an integer to an unicode character in Python?
unichr(x)
To write the workbook "wb" to disk as "new.xlsx", you would use
wb.write("new.xlsx")
To add a value "x" to a dictionary called "words" linked to "a", you would use
words["a"]="x"
An Excel spreadsheet document is called a
workbook
An example of setting "x" to a list that contains the numbers 1, 2, 3 is
x=[1,2,3]
To create a compressed archive of files, you can use the
zipfile library