Python: What Did You Learn?
If df is a DataFrame that includes a column 'year', what does `df.groupby('year') do?
Returns a special Pandas object - a grouped DataFrame - that lets us apply aggregations, such as sum() or max(), to each group separately
What do you need to type to execute a cell of code in Jupyter?
Shift+Enter
Which generality best describes the pandas dialect of Python?
Statements are formed by concatenating one .method after another
How does a DataFrame in pandas differ from a record array in NumPy?
The DataFrame has an index that can be any data type.
What is the advantage of using the NumPy version of mathematical functions, rather than the ordinary Python versions?
The NumPy versions can operate on all elements of an array at once
If the string "Station To Station" is assigned to a record array field of dtype 'U6', what happens?
The field stores the string 'Statio'
What happens if you do not specify column names when loading a file into a DataFrame?
The names of the columns are taken from the first record
How would you start the Anaconda Python shell?
Type "Python" into the Anaconda shell
Which of the following returns array([0. , 0.25, 0.5 , 0.75, 1. ])?
np.linspace(0,1,5)
Which of the following is NOT a legal way to create a Pandas DataFrame?
pd.DataFrame(integer=[1,2,3], square=[1,4,9])
Which range construct would generate the values 2,7,12, and 17?
range(2, 18,5)
What does the DataFrame groupby operation perform?
segregation
What is the benefit of using comprehensions?
shorter, more intuitive code that uses less memory
In addition to the actual data, what information is used by np.genfromtext?
the width of each field, the name of each field, the data types, and the stripping option
What is the purpose of NumPy?
to enable the use of arrays and permit compatibility with FORTRAN and C
Which of the following is NOT a common use of tuples in Python?
As vectors of numbers that can be summed: for example (1,2,3)+(4,5,6)
Why is the list constructor commonly used to find an index of an array element?
.index only works with lists
Which values does range(5, 25, 5) iterate through?
5, 10, 15, 20
If we are working with a DataFrame df indexed by year, what would df.loc[1914:1918] return?
A DataFrame including all rows between index 1914 and 1918 (included), if any
What is the difference between a list and a tuple?
A tuple cannot be modified
What does dict.items(), where dict is a Python dictionary, iterate over?
All pairs (key, value) from the dictionary
How do you sort the DataFrame DATA according to elements of the column name 'year' in the order of descending years?
DATA.sort_values('year', ascending=False)
Jim wants to extend his ability to use Python for data science. Why should he learn pandas?
It is rapidly becoming the most popular method for data analysis using Python
What is required for a dictionary key to be valid?
It must be unique and hashable
What does ["one", "two", "three"][-4] return?
It throws the exception IndexError: list index out of range
What is one advantage of classes over named tuples?
You can define methods for classes
What does [10 + k for k in range(10) if k % 2 == 0] return?
[10, 12, 14, 16, 18]
What array does np.ones((3,3)) * np.linspace(0,1,3) return?
[[0, 0.5, 1], [0, 0.5, 1], [0, 0.5, 1]]
If a = np.array([0,1,3,5,7,11]), what is a[a > 3]?
array([5, 7, 11])
An array has dimensions 1000,1000,1. Which specification is equivalent to array[850,750,0]?
array[-150,-250,0]
Numpy arrays of numerical values are generally stored _____.
as contiguous blocks of memory
How does np.interp work?
by linear interpolation
How can you avoid edge or end effects when using np.correlate?
by specifying the key 'valid'
If df is a DataFrame that includes a column 'x', what is NOT a way to add a new column 'y', using a function 'f' that applies a transformation?
df.y = f(df.x)