Lesson 10-19 Final Review Flashcards
True or False, A try block can be used to detect and handle a file not found error, when trying to open a file for reading.
True
True or False, The open() function can be used in order to read as well as write to files.
True
True or False, The open() function will read the contents of a file into a variable.
True
True or False, The readline() method will return an empty string when there is no more data to read from a file.
True
True or False, The string split() method only recognizes the comma as a delimiter
False
True or False, The string split() method returns a string result.
True
True or False, The result of the open function can be used as part of a for statement to loop over and read each line of a file.
True
True or False, The statements in an except block will get executed.
False
Which of the following methods can be used to read a line of a file into a string variable?
A.getline()
B.readline()
C.open()
D.all of the above
B.readline()
True or False. In order to read a file in Python, the open() function can be used to connect a variable with the file.
True
A function that can be used to write data to a file is:
A.write()
B.print()
C.save()
B. print()
After all lines of a file have been read, what will a subsequent call to readline() return?
A.
B.”(empty string)
C.0
D.an error
B. “(empty string)
Before writing to a text file, what function should be called, to associate a variable with the file?
A.input()
B.print()
C.open()
D.write()
C.open()
The primary Python keywords for detecting and handling an exception are:
A.try,except
B.if,else
C.for,while
D.input,print
A. try, except
The string returned by the readline() method includes which character at the end of the returned string?
A.\n
B.\t
C.
D.'
A.\n
Which function can be used to write items to a text file?
A.print()
B.input()
C.write.Line()
D.save()
A.print()
After all lines have been written to a file, what method should be called, to ensure all lines have been saved?
A.open()
B.close()
C.save()
D.end()
B. close()
Which statement can be used to associate a text file with a Python variable for subsequent reading?
A.f = open()
B.f = open(‘r’,’input.txt’)
C.f = open(‘input.txt’,’r’)
D.’input.txt’.open()
C.
The print() named parameter for specifying what to place between each item is:
A.delim
B.sep
C.csv
D.fieldsep
B.sep.
The string split() method returns what type?
A.a string
B.an int
C.a float
D.a list
D.a list
An example where Python will generate an exception is:
A. The last item returned from range()
B.A call to open() to read a file that does not exist
C.An infinite loop
D.The use of break in a repetition body
B.
The pandas function that can read a comma separated file’s data into a DataFrame is:
A.load_data()
B.read_csv()
C.read_data()
B. read_csv()
True or False: When reading data from a file into a DataFrame, the data must be separated by commas.
False
True or False: The head() and tail() methods can only show one row of a DataFrame’s data.
False
Which can be used to determine the number of columns in a DataFrame? (select the best, most complete, answer)
A. the len() function
B.the shape property
C.the info() method
D. the shape property and info method
E. the shape property and len() function
F.the shape property, info() method, and the len() function
F.
The pandas type for storing tabular data is called a:
A.DataFrame
B.table
C.ptable
D.Worksheet
A. DataFrame
True or False: Python has a built-in table data structure
False
True or False: Values in pandas Series cells are limited to int, float, and str types.
False
What type of result is returned by the DataFrame head() method?
A.DataFrame
B.Series
C.List
D.Dictionary
A.DataFrame
What does the DataFrame shape property indicate?
A.The number of rows and columns of the DataFrame
B.If the DataFrame is rectangular or another shape
C.The number of empty cells in the DataFrame
D.none of these
A.
One approach to determine the number of missing values in a DataFrame is to:
A. the info() method
B.use the missing method
C.use for repetition and count the number of None values
D.find the total of each column
A. the info() method
True or False: Each DataFrame column optionally has a name
False
True or False: For efficiency, pandas uses the Python float type to represent numbers.
Flase
What pandas function can be used to read a tabular text file and return a DataFrame?
A.read_csv()
B.read_data()
C.read_text()
D.load_data()
A.read_csv()
True or False,Pandas main focus is on non-tabular data.
False
True or False: The pandas read_csv() function requires files to in CSV (comma-separated value) format.
False
In order to sort a DataFrame without creating a new DataFrame, the parameter specified is:
A.inplace
B.ascending
C.newframe
D.copydf
A.inplace
The tolist() method returns:
A. a list from a series
B.a series from a list
C.a series from a DataFrame
D.None of these options
A.
If df is a DataFrame, and ‘colname’ is one of its column names, the expression df[‘colname’] returns:
A.a DataFrame
B.a Series
C.a Python List
D.None of these options
B. a Series
If df is a DataFrame, and ‘colname1’ and ‘colname2’ are two of its column names, the expression df[[‘colname1’, ‘colname2’]] returns:
A.a DataFrame
B.a Series
C.a Python List
D.None of these options
A. a DataFrame
The method to sort a DataFrame is:
A.sort()
B.sorted()
C.sort_values()
D.order()
C.sort_values()
If df is a DataFrame, and colname is one of its columns, which is a valid filter expression? (Select the best, most complete, answer)
A. df[df.colname==100]
B. df[df[‘colname’]==100]
C.df[colname==100]
D. None of the options
E. All the options
F. Both A&B
F. A&B
If df is a DataFrame, and ‘rowname’ is a name of one of its rows, which expression returns a row of the DataFrame?
A. df.iloc[‘rowname’]
B. df.loc[‘rowname’]
C. df.rowname
D. None of the options
E. All of the options
B.
How can values in a pandas Series method be accessed as a Python list?
A.using the tolist() method
B.using the getlist() method
C.using the list constructor
D.any of these
A. using the tolist() method
For a DataFrame df, how can its first row be accessed?
A. df.iloc[0]
B. df[0]
C.df.loc[0]
D. any of these
A.
If df is a pandas DataFrame with a column named ‘Sales’, what type of result is returned by df[‘Sales’] ?
A.pandas Series
B.a list
C.a dictionary
D.a pandas DataFrame
A. Pandas Series
For several methods, pandas provides the ____named parameter, to indicate whether a new DataFrame is returned, or an existing DataFrame is updated.
inplace
If df is a pandas DataFrame with a column named ‘Sales’, what expression is an example of a filter expression?
A. df[df.Sales > 100]
B. df.filter(‘Sales > 100’)
C. [df.Sales > 100]
D. filter(Sales > 100)
A.
How can one row of a DataFrame be accessed?
A. using the .loc[] accessor
B. using the column name
C. using curly braces
D. none of these
A.
Which DataFrame method can be used with for, to iterate over the rows of a DataFrame?
A.iterrows()
B.row()
C.for()
D.index()
A. iterrows
What is the purpose of descriptive analytics in an analytics project?
A.To predict future outcomes
B.To prescribe actions based on data analysis
C.To summarize and understand what has happened or is happening
D.To transform and standardize data
C.
What is a reason for standardizing data?
A.To predict future outcomes accurately
B.Enable meaningful comparisons regardless of scale of the original data
C.To summarize data and understand trends
D.To identify outliers in the dataset
B.
What does the shape attribute of a DataFrame tell you?
A.The size of the DataFrame memory
B.The number of rows and columns in the DataFrame
C.The data types of the columns in the DataFrame
D.The unique values in the DataFrame
B.
What is the general syntax to use the describe() function on a column?
A.dataframe.describe(column_name)
B.column_name.describe()
C.describe(dataframe, column_name)
D.dataframe[‘column_name’].describe()
D.
What is the purpose of the describe() function?
A.Calculate the mean, median, and mode of a column
B.Generate graphical analysis such as bar charts and histograms
C.Provide summary statistics of a DataFrame
D.Apply advanced transformations to data
C.
What does the describe() method provide for a numerical column?
A.mean, median
B.minimum and maximum values
C.standard deviation and quartiles
D.All of the options
E.None of the options
D.
What does the unique() function in pandas do?
A.Returns the count of unique values in a column
B.Returns the unique values in a column
C.Returns the most frequent value in a column
D.Returns the average of unique values in a column
B. Returns the unqiue values in a column
What type of analytics tells us what is likely to happen next?
A.Descriptive Analytics
B.Predictive Analytics
C.Prescriptive Analytics
D.Explanatory Analytics
B.
How can you read an Excel file into a pandas DataFrame?
A.pd.read_excel(‘filename.xlsx’)
B.pd.read_csv(‘filename.csv’)
C.pd.read_file(‘filename’)
A.
How can you insert a new column into a specific position in a DataFrame?
A.add_column()
B.insert()
C.new_column()
D.append_column()
B.insert()
What is the purpose of the tail() function in pandas?
A.Group data based on specified fields
B.Display the first few rows of the DataFrame
C.Calculate summary statistics
D.Display the last few rows of the DataFrame
D.
What does the shape function return for a DataFrame?
A.Total number of rows and columns
B.Number of unique values in each column
C.Summary statistics for each column
D.The first few rows of the DataFrame
A.