DANL chapter 2-9

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following concatenates a sequence of elements of a list into a string separated by a space?

" ".join(seq)

What gets printed? numbers = [1, 2, 3, 4] numbers.extend([5,6,7,8]) print(len(numbers))

8

The expression used to check the value of A is equivalent the value of B in Python is

A == B

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

Which type of chart would be best for displaying a categorical variable?

Bar chart

What chart would be best for showing values over a given area or region?

Choropleth

Chord diagrams are good for displaying the

Connections between items

Scatterplots are good for displaying the

Correlation between two variables

What chart type would be best for showing the distribution of a variable?

Density

Histograms are good for displaying the

Distribution of a variable

What does the while statement do?

Execute a block of commands until the Boolean condition becomes False

Given X="ABCDEFGHIJKLMNOPQRSTUVWXYZ", X[5:19:2] is?

FHJLNPR

Code indentation must be exactly 4 spaces when creating a code block.

False

In a dictionary, you can set multiple values to the same key.

False

The "add" method adds elements to the end of a list.

False

Which type of chart would be best for displaying a variable over time?

Line graph

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.

To find out where a program is operating, you can use the the following function from the pathlib Path object

Path.cwd()

Donut graphs are good for displaying the

Percentage of values within a variable

What does the "short-circuit rule" refer to?

Python logical expressions resolve to the answer when no more can be gained from evaluating the rest of the expression

Lollipop plots are good for displaying the

Ranking of values within a variable

What chart would be best for showing the flow of a variable between two or more states?

Sankey

A one-dimenstional array-like object in pandas is called a

Series

What is an example of the accumulator pattern?

Starting a variable with the initial value, updating the variable with its own value over and over

Given X="ABCDEFGHIJKLMNOPQRSTUVWXYZ", X[19:6:-2] is?

TRPNLJH

What is wrong with this code? for i in range(1,10,1): print(i)

The print statement needs to be indented

What is wrong with this code? for i in range(10,1,1): print(i)

The range should be range(10,0,-1)

What is wrong with the following code? def averege(numbers): return sum(numbers)/len(numbers)

The return should be indented

What is wrong with this code? for i in range(1,10,1): print(i)

There is nothing wrong with the code

Why would you use the "try" and "except" reserved words?

To safeguard your program from unexpected runtime errors

Indentation is important when using the if statement.

True

MyData32 is a valid variable name.

True

_MyData32 is a valid variable name.

True

Which of the following is a valid Python variable name?

X52_662zeta

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[25:18:-3] is?

[25, 22]

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[6:8:2] is?

[7]

The worksheet that is currently (or most recently) viewed is called the

active sheet

What is the following compares elements of both lists?

cmp(list1, list2)

The "on" option of pd.merge determines the

column names to use as the keys for merging

To bring all the content of a file into a Python program, you would use a Python statement like

contents = fhandle.read()

Casting is

converting from one data type into another

To separate a Series into a set of buckets, you can use the method

cut()

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 values from a dictionary called d?

d.values()

For reading dates in European format (dd-mm-yyyy), you would add the option to read_csv()

dayfirst=True

f = lambda x: x.max() - x.min()

defines a function called f that calculates the range

To calculate the statistics of a pandas DataFrame, you can use the method

describe()

To read data from comma delmited values from a file called "data.dat" into pandas, you would use

df = pd.read_csv("data.dat")

To read data from a data file "data.xlsx" into pandas, you would use

df = pd.read_excel("data.xlsx")

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 caluclate the averages of a DataFrane df, you use

df.mean()

To sort a dataframe df by its content, you use

df.sort_values()

To sort the "df" dataframe on the primary column key "ID" and second column key "Date", you can use

df.sort_values(by=["ID","Date"])

To find the distribution of values of column 'a' in dataframe df, you use

df["a"].value_counts()

To remove replicated data, you can use the method

drop_duplicates()

The Python object for working with a file is called a

file handle

To set missing values to a set value, you can use the method

fillna()

The statement "something wrong = 5"

generates "SyntaxError: invalid syntax" error

To include functions from a module, you use

import

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

What is the following gives the total length of the list?

len(list)

What is the following inserts an object at given index in a list?

list.insert(index, obj)

What is the following removes an object from a list?

list.remove(obj)

To perform a calculation on every element of a Series, you can use

map()

Which of the following convert a single character to its character code (as an integer) in Python?

ord(x)

To find out what files and directories are in a directory, you would use

os.listdir()

When you are finished with using a file handle called output in Python, you should call the function

output.close()

The location of a file is known as the

pathname

To stack two DataFrames (df1 and df2), you can use

pd.concat([df1,df2])

To convert a "wide" formatted dataframe "df" to a "long" format on "key", you can use

pd.melt(df,["key"])

To include rows from both DataFrames (df1 and df2), no matter which dataframe the data is in, you use

pd.merge(df1,df2,how="outer")

The operator for division is

plain] /

Which of the following functions convert a string to a set in Python?

set(x)

The statement "something = 1,"

sets the variable 'something' to (1,)

To ignore the last top 20 lines at the end of a file, you would add the option to read_csv()

skip_footer=20

Which of the following convert an integer to an unicode character in Python?

unichr(x)

Which of the following converts a string to all uppercase?

upper()

To write the workbook "wb" to disk as "new.xlsx", you would use

wb.save("new.xlsx")

To get a list of sheets in an Excel workbook called "wb", you would use

wb.sheetnames

To add a value "x" to a dictionary called "words" linked to "a", you would use

words["a"] = "x"

To create a compressed archive of files, you can use the

zipfile library


Conjuntos de estudio relacionados

CompTIA A+ (220-1102) quizzes 1-5

View Set

Busi 1307- Personal Finance Chapter 6 Quiz

View Set

Theatre Appreciation- Chapter 11

View Set