Lesson 10-19 Flashcards

1
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: The open() function can be used in order to read as well as write to files.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False: The open() function will read the contents of a file into a variable.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or False: The readline() method will return an empty string when there is no more data to read from a file.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or False: The string split() method only recognizes the comma as a delimiter

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False: The string split() method returns a string result.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: The statements in an except block will get executed.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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 the above

A

B. readline()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

True or False: In order to read a file in Python, the open() function can be used to connect a variable with the file.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

A function that can be used to write data to a file is?
A. write()
B.print()
C.save()

A

B.print()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

After all lines of a file have been read, what will a subsequent call to readline() return?
A.\n
B.’’ (empty string)
C.0
D.an error

A

B.”(empty string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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()

A

C. open()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The primary Python keywords for detecting and handling an exception are:
A. try, except
B. if, else
C. for, while
D. input, print

A

A. try, except

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

After using the open() function, which method can be used to read a line from a text file?

A.readtext()
B.readline()
C.readlin()
D.readnext()

A

B. readline()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The string returned by the readline() method includes which character at the end of the returned string?

A.\n
B.\t
C.double backspace
D.single backspace

A

A.\n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Which function can be used to write items to a text file?
A.print()
B.input()
C.write.Line()
D.save()

A

A.print()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

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()

A

B. close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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()

A

C.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

The print() named parameter for specifying what to place between each item is:
A. delim
B. sep
C. csv
D. fieldsep

A

B. sep

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

The string split() method returns what data type?

A. Series
B. DataFrame
C. List
D. A string

A

List

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

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 repeition body

A

B.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

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()

A

B. read_csv()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

True or False: When reading data from a file into a DataFrame, the data must be separated by commas.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
True or False: The head() and tail() methods can only show one row of a DataFrame’s data.
False
26
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. All the above
D. All the above
27
The pandas type for storing tabular data is called a:
DataFrame
28
True or False: Python has a built-in table data structure
False
29
True or False: Values in pandas Series cells are limited to int, float, and str types.
False
30
What type of result is returned by the DataFrame head() method? A.DataFrame B.Series C.Method D.List
A. DataFrame
31
What does the DataFrame shape property indicate?
The number of rows and columns of the DataFrame
32
If df is a DataFrame, what does len(df) return?
The number of rows of df
33
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
34
True or False: Each DataFrame column optionally has a name
False
35
What DataFrame method returns its last rows?
tail()
36
In order to use pandas in your program, you need to use the ___ statement.
import
37
True or False: For efficiency, pandas uses the Python float type to represent numbers.
False, the correct answer is "NumPy float64" instead of "float"
38
What pandas function can be used to read a tabular text file and return a DataFrame?
read_csv
39
True or False:Pandas main focus is on non-tabular data.
False (pandas provides tools for collecting, transforming, and analyzing tabular data)
40
Which DataFrame method returns its first rows?
head()
41
True or False: The pandas read_csv() function requires files to in CSV (comma-separated value) format.
False (read_csv() can be used to read files with data separated by commas or other delimiters such as spaces or tabs)
42
In order to sort a DataFrame without creating a new DataFrame, the parameter specified is:
inplace
43
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. a list from a series
44
If df is a DataFrame, and 'colname' is one of its column names, the expression df['colname'] returns:
A series
45
If df is a DataFrame, and 'colname1' and 'colname2' are two of its column names, the expression df[['colname1', 'colname2']] returns:
A DataFrame
46
The method to sort a DataFrame is:
sort_values()
47
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. None of the options D. Both A & B
D.
48
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. df.loc['rowname']
49
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
50
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. df.iloc[0]
51
If df is a pandas DataFrame with a column named 'Sales', what type of result is returned by df['Sales'] ?
A Pandas series
52
What DataFrame method returns a sorted DataFrame?
sort_values()
53
For several methods, pandas provides the ____named parameter, to indicate whether a new DataFrame is returned, or an existing DataFrame is updated.
inplace
54
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.
55
For a DataFrame df with a column named 'Sales' and a row index named '2023', what expression will access the Sales for 2023? A.Either of these B. df['Sales']['2023'] C.df.loc['2023']['Sales']
A.
56
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. using the .loc[] accessor
57
Which DataFrame method can be used with for, to iterate over the rows of a DataFrame?
iterrows()
58
Suppose you have the following DataFrame and field names: DataFrame name: studentGrades Field/column Names: student name, quiz1, quiz2, exam1, exam2 Write the python pandas code that will give descriptive analytics (count, mean, standard deviation, min, max, quartiles) for each numerical series in the dataframe.
studentGrades.describe()
59
Given the following DataFrame and field/column names write the python pandas code that shows the number of reviews by taster. DataFrame name: wineReviews Field/column names in winReviews: country, description, designation, points, price, province, taster_name, title, variety, winery Don't define a variable name for this just write the code to show the output Use bracket selection (not dot notation) to select the field names
wineReviews['taster_name'].value_counts()
60
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.
61
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.
62
What does the shape attribute of a DataFrame tell you?
The number of columns and rows in the Dataframe
63
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.
64
What is the purpose of the describe() function?
Provide summary statistics of a DataFrame
65
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
D.
66
What does the unique() function in pandas do?
Returns the unique values in a column
67
What does the head() function in pandas do?
Returns the first 5 rows of the DataFrame
68
What type of analytics tells us what is likely to happen next?
Predictive Analytics
69
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.
70
How can you insert a new column into a specific position in a DataFrame? a) df.insert() b) df.add_column() c) df.new_column() d) df.column_insert()
a. df.insert()
71
What is the purpose of the tail() function in pandas?
To dislay the last few rows of data of the DataFrame
72
What does the shape function return for a DataFrame?
Total number of rows and columns
73
Using the sort_values() method, how can you sort the results of a groupby operation in descending order? A.By setting the ascending parameter to True B.By using the sort_values() function C.By using the get_group() function D.By setting the ascending parameter to False
D.
74
Which function is used to sort data in pandas?
sort_values()
75
How can you set a specific column of a DataFrame as its index? a) df.index('column_name') b) df.set_index('column_name') c) df.index_as('column_name') d) df.index_set('column_name')
B. Using the set_index() function
76
What is the purpose of the agg() function in pandas? A.Sort data in ascending order B.Group data based on specified fields C.Calculate summary statistics D.Filter data based on conditions
C.
77
What is the purpose of the groupby() function in pandas? a) To merge two DataFrames based on a common column b) To sort the DataFrame based on specified columns c) Group rows of data based on specified fields
c) Group rows of data based on specified fields
78
What does the dropna parameter do in the groupby() method? A.Controls whether to show observed values for categorical groupers B.Controls whether to drop NA values together with row/column C.Controls whether to sort group keys D.Controls whether to return object with group labels as the index
B.
79
What is the default sorting order of sort_values() in pandas?
Ascending order
80
True or False: The groupby() function returns a new DataFrame containing the grouped data.
False
81
To sort a DataFrame based on one or more columns, we can use the sort_values() function with the parameter by='column_name' and specify the column(s) we want to ____ by.
sort
82
What parameter of the groupby() method is used to determine the groups for grouping a DataFrame in Python?
by
83
By default, which of the following statements is true about sort_values() in pandas? A.It modifies the original DataFrame B.It can only sort by a single column. C.It returns a new DataFrame with the sorted data. D.It requires the columns to be of string data type.
C.
84
In the sort_values() function, which sorting algorithm is the default choice for the kind parameter?
quicksort
85
In the groupby() method, if the sort parameter is set to False, what does it affect? A.The order of observations within each group B.The order of rows within each group C.The order of columns within each group D.The order of group keys
D.
86
What is the purpose of the sort_values() method in pandas? A.To sort a DataFrame based on the values along a specified axis. B.To sort a DataFrame based on the index labels. C.To sort a DataFrame based on column levels. D. To sort a DataFrame based on multiple sort orders.
A.
87
The groupby() function in Pandas is used to ___ a DataFrame based on one or more columns
group
88
What is the purpose of the as_index parameter in the groupby() function? A.It specifies the column(s) to group by B.It determines whether the groups should be treated as separate dataframes. C. It determines the sorting order of the groups D.It sets the index of the resulting grouped DataFrame
D.
89
Which parameter in the sort_values() function specifies the name or list of names to sort by?
by
90
What is the default value for the ascending parameter?
True
91
True or False:The groupby() function can be applied to multiple columns by passing a list of column names to the by parameter, like df.groupby(by = ['column1', 'column2']).
True
92
To sort a DataFrame in descending order, we can set the parameter ascending of the sort_values() function to ___.
False
93
What does the dtypes() method return for a pandas DataFrame?
The data types of the columns in the DataFrame
94
Which method is used to check whether a value in a pandas DataFrame is null or missing?
isnull()
95
What does the replace() method do in pandas? A.Replaces all values in a DataFrame with a specified value B.Replaces specific values in a DataFrame with other specified values C.Replaces missing values with a specified value in a DataFrame D.Replaces the data types of columns in a DataFrame
B.
96
For numeric columns, pandas uses what value to represent missing data?
NumPy NaN
97
What method can be used to locate DataFrame cells with missing data? A.ismissing() B.isna() C.novalue()
B. isna()
98
What does the isnull() function in Python return? A. True if the value is null, False otherwise B.True if the value is non-null, False otherwise. C. True if the value is missing, False otherwise. D. None of these options
A.
99
Which method is designed to replace missing values in a pandas DataFrame with a specified value? a) df.replace_na() b) df.fillna() c) df.replace_missing() d) df.null_fill()
B. df.fillna()
100
Which method can be used for replacement when the to_replace parameter is a scalar, list, or tuple, and the value parameter is None? A. 'pad' B. 'ffill' C. 'bfill' D. All of the above E. None of the above
D.
101
If the limit parameter is set to a value greater than 0 in the fillna() function, what does it indicate? A. The maximum number of entries along the entire axis where NaNs will be filled B. The maximum number of consecutive NaN values to forward/backward fill C. The maximum number of columns to fill with NaN values D. The maximum number of rows to fill with NaN values
B.
102
What is the default value of the inplace parameter in the replace() function?
False
103
Which method involves imputing missing values with the overall mean of the feature?
Mean Replacement
104
Which method involves replacing missing values with an educated guess based on the analyst's expertise in the area? A. Use prior knowledge to estimate the value B. Median replacement C.Mean replacement D.Regression replacement
A.
105
What should be done regardless of the method used for missing data? (a) Create a new feature indicating if missing data was imputed (b) Repeat the analysis with and without missing data (c) Use regression replacement for imputing missing values (d) Remove all records with missing data (e)All of the options (f) (a) and (b)
F.
106
What does the fillna() function in pandas return when the inplace parameter is set to True?
None
107
Which parameter in the fillna() function specifies the method to use for filling missing values? a) method b) strategy c) fill_type d) mode
A. method
108
Which parameter of the replace() function in Python's pandas library is used to specify the values that will be replaced? a) old_value b) target c) to_replace d) substitute
C. to_replace
109
Which method can be used to process each value of a given column? a) each() b) apply() c) lambda()
B. apply()
110
A category column can be created using which method? A. category() B.astype() C. unique()
B.astype()
111
Which can be used to review the datatype of a DataFrame Column A. the dtype Property B.the info() method C. the python type() function D. Both A&B
D.
112
The method to display the set of values occurring in a data frame column is: A. occuring() B. unique() C. tolist()
B.
113
What method can be used to see which rows have duplicate values within a certain column?
the duplicated() method
114
Which can be used to see if a column has unique values?
the is_unique property
115
Assume a Python list has valid values for a given data frame column. To create a new data frame column indicating which rows have valid values, we can use: A. the split method() B. a lambda method with an in expression C. list slicing
B.
116
New string columns can be created from a single data frame column using which method?
split()
117
True or False: A lambda function can be used in combination with the pandas apply() method.
True
118
The pandas DataFrame method that can be used to filter out duplicate values is: A. drop_duplicates() B. filter_repeats() C. drop_matched() D. filter_matched()
A.
119
Which is not a rule for read_csv() as related to numbers: A. If a column has integer values and some missing values, pandas will use the Python int type or None for the values in the column B.If any value of a column is non-numeric, the column's values are represented as Python types as opposed to NumPy types C. If all values in a column are numeric and any value has decimal places, the column is represented as a NumPy float
A.
120
For a pandas DataFrame df, which expression can be used to find rows with missing values for the column named id? A. df[df.id.isna()] B. df.id.isna C. df.id.False D. df.missing('id')
A.
121
Which pandas method can generate category labels based on numeric ranges? a) pd.cut() b) pd.label() c) pd.bucket() d) pd.range()
A. pd.cut()
122
Which pandas Series method generate the set of unique values in a Series?
unique()
123
Which pandas method can create numeric values?
to_numeric()
124
Which pandas method can be used to filter out rows with missing values? a) dropna() b) filter() c) isnull() d) exclude()
A. dropna()
125
Which pandas method can create Timestamp values?
to_datetime()
126
Which is a valid pandas expression, to create a new column in percent from another column in decimal? A. df['tax_pct'] = df['tax_dec'] * 100 B. df['tax_pct'] *= 100 C. df['tax_pct'] = df.scale('tax_dec', 100) D. df['tax_pct'] = df.tax_dec % 100
A.
127
True or False: For data preparation, replacing original data as opposed to creating new data is generally preferred.
False
128
What type of argument is provided to the pandas apply() method? A. function B.string C.list D.dictionary
A. function
129
Which pandas Series method can be used to generate several string columns from a single column
str.split()
130
Inter-field validity checks can be implemented with A. DataFrame filter expression B. the DataFrame apply() C. Both of these
C.
131
The Series method to return which rows have duplicated values is: a) find_duplicates() b) duplicated() c) dup_rows() d) repeat_rows()
b. duplicated()
132
What pandas Series property indicate the type used for the data?
dtype
133
Which pandas method can be used to create a column with a particular NumPy datatype size? a) df['column_name'].type() b) df['column_name'].cast() c) df['column_name'].astype() d)df['column_name'].change_type()
c. astype()
134
Which pandas DataFrame method can be used to generate a new DataFrame with a different organization of the data? A. Melt() B.transpose() C. pivot() D. All the above
D.
135
Which Series property indicates if its values are distinct? a) is_distinct b) is_unique c) unique d) distinct
B. is_unique
136
What keyword begins the definition of a lambda function?
lambda
137
What is the purpose of the axis parameter in the concat() method? A.It specifies the columns to be concatenated. B.It specifies the rows to be concatenated. C.It specifies the axis to concatenate along. D.It renames the index labels of the concatenated DataFrame.
C. It specifies the axis to concatenate along.
138
Which parameter of the merge() method specifies the type of merge to be performed? a) merge_type b) join_type c) how d) method
C. how
139
Which of the following statements about the concat() method in pandas is correct? (select all that apply) A.concat() is used to combine two or more DataFrames vertically B.concat() is used to combine two or more DataFrames horizontally C.concat() is used to sort a DataFrame in ascending order D.concat() is used to rename columns in a DataFrame.
A & B
140
Which parameter of the DataFrame.join() method specifies the columns to join on?
on
141
What does the indicator parameter of the merge() method do? A. Adds a column to the output DataFrame indicating the source of each row B.Sorts the join keys lexicographically in the result DataFrame C. Specifies the column names to be added as suffixes to overlapping columns D. Determines whether a copy of the merged objects is created
A.
142
What is the default value for the 'how' parameter in the DataFrame.join() method?
Left
143
Which of the following statements is true about the pandas.DataFrame.join method? (select all that apply) A.The join method performs a merge operation based on the index labels of the two DataFrames. B.The join method performs an inner join by default. C.The join method supports joining on multiple columns. D. The join method modifies the original DataFrame in-place
A & C
144
Which parameter determines the axis to concatenate along in the pandas.concat function?
axis
145
When concatenating all Series along the index (axis=0) in the pandas.concat function, what type of object is returned?
Series
146
What is the default join type used in the merge() function in Pandas?
Inner join
147
What does the 'sort' parameter of the DataFrame.join() method control? A.Sorting the resulting joined DataFrame by the join key B.Sorting the columns of the left frame C.Sorting the columns of the right frame D.Sorting the index of the resulting joined DataFrame
A.
148
Which parameter of the DataFrame.join() method specifies the columns to join on?
On
149
Which parameters in the merge() function specifies the column(s) to merge on? A. left_on B. right_on C. on D. None of the Above E. All the above
left_on, right_on, on
150
What is the default value for the join parameter in the pandas.concat function? a) 'outer' b) 'inner' c) 'left' d) 'right'
A. 'outer'
151
What is the default value for the 'how' parameter of the DataFrame.join() method?
left
152
In a left join operation using merge(), what happens to the unmatched rows from the right DataFrame? A.They are included in the result with NaN values B.They are dropped from the result C.They are duplicated in the result D.They are excluded from the merge operation
A.
153
If the ignore_index parameter is set to True in the pandas.concat function, what happens to the index values along the concatenation axis? A.They are dropped silently B.They are replaced with sequential numbers. C.They are kept as they are. D.They are sorted in ascending order.
B.
154
Which method is used to combine DataFrame or named Series objects with a database-style join?
merge()
155
In order to visualize data in a pandas DataFrame, you can use: a) df.plot() b) df.visualize() c) df.show_graph() d) df.chart()
A. the plot() method
156
To review the distribution of data, the DataFrame plot() method's kind parameter can be set to: a) 'hist' b) 'table' c) 'text' d) 'details'
A. 'hist'
157
The named parameter of the DataFrame plot() method to select the type of chart is called:
kind
158
The default chart provided by pandas DataFrame is a:
line chart
159
In order to refine a pandas chart, you can use which package?
Matplotlib
160
A chart type for reviewing a potential relationship between two variables is:
scatter
161
Which pandas method can be used to generate a chart?
plot()
162
When generating a scatter chart using seaborn, which named parameters must be set?
x,y
163
True or False, Matplotlib statements can be used to refine a chart generated by pandas
True
164
What argument(s) can be provided to the pandas plot() method to generate a stacked bar chart? A. kind='stacked_bar' B.kind='bar', stacked=True C.type='bar', subtype='stacked' D.type='stacked bar'
B. kind='bar', stacked=True
165
Which package can be used with seaborn to refine the generated chart?
Matplotlib
166
To generate a dual Y axis line chart, which named parameter is passed to the pandas() plot() method? A. dualy B. y2 C. secondary_y D. None of these
C.
167
The DataFrame plot() method has the named parameter ____ , which is set to get a particular type of chart.
kind
168
When generating a histogram with pandas plot(), which named parameter controls the number of bins?
bins
169
When creating a chart, by default pandas generates a line chart with the DataFrame's ____ for the X axis.
index
170
Describe Descriptive Analytics
Tell us what has happend or what is happening
171
Describe Predictive Analytics
Tells us what is likely to happen next
172
Describe Prescriptive Analytics
Tells us what to do based on the analysis
173
Is shape an attribute or method
attribute
174
Is size an attribute or method
attribute
175
Is head() an attribute or method
method
176
str.replace() is an attribute or method
method
177
dtypes is an attribute or method
attribute
178
read_csv() is an attribute or method
method
179
Is the map() method compatiable with: Series, DataFrames, or Both
Only Series
180
Is the apply() method compatiable with: Series, DataFrames, or Both
Both: Series & DataFrame
181
Is the applymap() method compatiable with: Series, DataFrames, or Both
Only DataFrames