Lecture 1 and 2
<question>What is the output of the following code?
t = (1, 2, 3) + (4, 5)
print(t)
<variant> (1, 2, 3, 4, 5)
<variant> (5, 4, 3, 2, 1)
<variant> [1, 2, 3, 4, 5]
<variant> (1, 2, 3), (4, 5)
<question>What method is used to remove a specific value from a list?
<variant> remove()
<variant> pop()
<variant> delete()
<variant> del
<question>The ______ function returns a new sorted list from any sequence.
<variant> sorted
<question>The update method is used to merge one dictionary into another.
<variant> True
<variant> False
<question>Which method is used to check if a dictionary contains a specific key?
<variant> in
<variant> contains()
<variant> has_key()
<variant> key_check()
<question>The pandas library provides high-level data structures for working with structured and
tabular data.
<variant>True
<variant>False
<question2>Which of the following is a mutable object in Python?
<variant>String
<variant>Tuple
<variant>List
<variant>None
<question> What will be the output of this code? x = 10; y = 3; print(x // y)
<variant> 3.33
<variantright> 3
<variant> 3.0
<variant> 4
<question> Output of this code:
nums = [1,2,3]
print(sum(nums))
<variantright> 6
<variant> 5
<variant> 3
<variant> Error
<question> What does the following code print?
a = [1,2,3]
print(a[::-1])
<variantright> [3,2,1]
<variant> [1,2,3]
<variant> [1,3,2]
<variant> Error
<question> Output of this code:
d = {"a":1, "b":2}
print([Link]("c", 0))
<variantright> 0
<variant> None
<variant> Error
<variant> 2
<question> What does the following code return?
lst = [1,2,3,4]
print([Link](3))
<variantright> 2
<variant> 3
<variant> 1
<variant> Error
<question> The with statement is used to handle ______ safely and ensure they are closed properly.
<variantright> files
Lecture 3. NumPy Basics
<question>Which of the following is **not** a valid input for creating a DataFrame?
<variant>A single integer
<variant>A dictionary of lists
<variant>A NumPy array
<variant>A list of dictionaries
<question> What is the output of the following code?
import numpy as np
a = [Link]([1, 2, 3])
print(a[1])
<variantright> 2
<variant> 1
<variant> 3
<variant> Error
<question> What does this code print?
import numpy as np
a = [Link]([[1, 2], [3, 4]])
print([Link])
<variantright> (2, 2)
<variant> (2,)
<variant> (4,)
<variant> Error
<question> Output of the following code?
import numpy as np
a = [Link]([1,2,3])
print([Link])
<variantright> int64
<variant> float64
<variant> object
<variant> Error
<question> What is the result?
import numpy as np
a = [Link]((2,3))
000
000
<question> Output of this code?
import numpy as np
a = [Link]([1,2,3,4])
print([Link](a>2))
<variant> (array([2,3]),)
<variant> (array([0,1]),)
<variantright> [3 4]
<variant> Error
<question> What does this print?
import numpy as np
a = [Link]([1,2,3,4])
print([Link]([1,2,2,3,3,4]))
<variantright> [1 2 3 4]
<variant> [1 2 2 3 3 4]
<variant> [2 3 4]
<variant> Error
Lecture 4. Getting Started with pandas
<question>What is a key difference between a pandas `Series` and a `DataFrame`?
<variant>A `Series` is one-dimensional, while a `DataFrame` is two-dimensional.
<variant>A `Series` can contain multiple data types, while a `DataFrame` cannot.
<variant>A `DataFrame` does not have indexes, while a `Series` always does.
<variant>Both `Series` and `DataFrame` are always empty by default.
<question>Which method allows you to select data from a DataFrame by row and column labels?
<variant>`loc`
<variant>`iloc`
<variant>`index`
<variant>`slice`
<question>What will the following code output?
```python
import pandas as pd
data = {"A": [1, 2], "B": [3, 4]}
df = [Link](data)
print([Link][1])
```
<variant>A 2,
B 4
<variant>A 1, B 3
<variant>[1, 3]
<variant>Error: No row with index 1
<question>What will the following code output?
```python
import pandas as pd
s = [Link]([1, 2, 3], index=["a", "b", "c"])
print(s["b"])
```
<variant>2
<variant>1
<variant>"b"
<variant>Error: Invalid index access
<question> What does this code return?
import pandas as pd
df = [Link]({'A':[1,2,3], 'B':[4,5,6]})
print(df[df['A']>1])
<variantright> A B
125
236
<variant> A B
014
<variant> [2,3]
<variant> Error
<question> Output of this code?
import pandas as pd
df = [Link]({'A':[1,2,3], 'B':[4,5,6]})
print([Link][1,1])
<variantright> 5
<variant> 2
<variant> 4
<variant> Error
<question> What does the following code produce?
import pandas as pd
df = [Link]({'A':[1,2,3], 'B':[4,5,6]})
print([Link][0,'B'])
<variantright> 4
<variant> 1
<variant> 0
<variant> Error
Lecture 5. Data Loading, Storage and File Formats
<question>Which library is typically used to read and parse Excel files in pandas?
<variant>openpyxl
<variant>pickle
<variant>lxml
<variant>json
<question>Which pandas method writes a DataFrame to pickle format?
<variant>to_pickle()
<variant>write_pickle()
<variant>to_binary()
<variant>pickle_dump()
<question>What will the following code do?
import pandas as pd
df = pd.read_excel('[Link]', sheet_name='Sheet1')
print([Link]())
<question> What does this code output?
import pandas as pd
df = pd.read_csv('[Link]', thousands=',')
<variantright> Converts numbers like '1,000' to 1000
<variant> Treats ',' as delimiter
<variant> Reads all values as strings
<variant> Error
<question> Output of this code?
import pandas as pd
df = pd.read_csv('[Link]', skip_blank_lines=True)
<variantright> Ignores blank lines in the CSV
<variant> Reads blank lines as NaN
<variant> Error
<variant> Deletes CSV
<question> What is the output of this code?
import pandas as pd
df = pd.read_csv('[Link]', low_memory=False)
<variantright> Prevents dtype guessing and ensures proper memory usage
<variant> Reads CSV in chunks
<variant> Converts everything to string
<variant> Error
<question> What does this code do?
import pandas as pd
df = pd.read_sql('SELECT * FROM table1', conn, index_col='ID')
<variantright> Reads SQL table and sets 'ID' as index
<variant> Writes SQL table
<variant> Converts SQL table to CSV
<variant> Creates a new SQL table
<question> What does this code do?
import pandas as pd
df = pd.read_csv('[Link]', header=span>None)
print([Link]())
<variantright> Reads CSV without using the first row as header
<variant> Reads CSV using the first row as header
<variant> Reads only the first row
<variant> Writes CSV without header
Lecture 6. Data Cleaning and Preparation
<question> How do you remove rows with all NaN values?
[Link](how='all', inplace=True)
<variantright> Drops rows where all values are NaN
<variant> Drops any row with NaN
<variant> Drops column with NaN
<variant> Fills NaN
<question> How can you strip special characters from a string column?
df['col'] = df['col'].[Link]('[^a-zA-Z0-9]', '', regex=True)
<variantright> Removes all non-alphanumeric characters
<variant> Converts to lowercase
<variant> Converts to uppercase
<variant> Replaces spaces with underscores
<question> Output of this code?
import pandas as pd
df = [Link]({'A':[1,2,3,4,5]})
Q1 = df['A'].quantile(0.25)
Q3 = df['A'].quantile(0.75)
IQR = Q3 - Q1
df_filtered = df[(df['A'] >= Q1 - 1.5*IQR) & (df['A'] <= Q3 +
1.5*IQR)]
print(df_filtered)
<variantright> Filters out outliers based on IQR
<variant> Keeps only outliers
<variant> Drops all rows
<variant> Error
<question> How do you replace all infinite values with NaN?
import numpy as np
[Link]([[Link], -[Link]], [Link], inplace=True)
<variantright> Replaces +inf/-inf with NaN
<variant> Drops infinite values
<variant> Converts to zero
<variant> Raises error
<question> What does this code do?
df['col'] = df['col'].[Link]()
<variantright> Converts all strings in the column to lowercase
<variant> Converts to uppercase
<variant> Strips spaces
<variant> Deletes column
<question> How can you remove columns with more than 50% missing values?
[Link](thresh=len(df)*0.5, axis=1, inplace=True)
<variantright> Drops columns with more than 50% NaN
<variant> Drops rows with >50% NaN
<variant> Replaces NaN with 0
<variant> Keeps only rows with >50% non-NaN
Lecture 7. Data Wrangling: Join, Combine and Reshape
<question> What does this code produce?
import pandas as pd
df1 = [Link]({'key':[1,2,3],'A':[10,20,30]})
df2 = [Link]({'key':[3,4,5],'B':[300,400,500]})
[Link]([df1, df2], axis=0, ignore_index=True)
<variantright> Stacks df1 and df2 vertically and resets the index
<variant> Stacks horizontally
<variant> Performs a merge
<variant> Produces an error
<question> What is the result of this code?
import pandas as pd
df = [Link]({'X':[1,2],'Y':[3,4]})
[Link](df, id_vars=['X'])
<variantright> Keeps 'X' fixed and unpivots 'Y' into long format
<variant> Keeps 'Y' fixed and unpivots 'X'
<variant> Drops column 'Y'
<variant> Produces an error
<question> What does this code do?
import pandas as pd
df1 = [Link]({'key':[1,2,3],'A':[10,20,30]})
df2 = [Link]({'key':[2,3,4],'B':[200,300,400]})
[Link](df1, df2, how='outer', on='key')
<variantright> Outer join: keeps all keys from both DataFrames, fills missing with NaN
<variant> Left join
<variant> Inner join
<variant> Right join
<question> Output of this code?
import pandas as pd
df = [Link]({'id':[1,1,2,2],'variable':
['X','Y','X','Y'],'value':[10,20,30,40]})
[Link](index='id', columns='variable', values='value')
<variantright> Reshapes from long to wide format with 'id' as index
<variant> Reshapes from wide to long
<variant> Drops column 'value'
<variant> Produces an error
<variantright> Left join: keeps all rows from df1, adds matching rows from df2
<variant> Inner join
<variant> Right join
<variant> Outer join
<question> What is the difference between merge and concat?
<variantright> merge joins based on columns or keys, concat stacks DataFrames along axis
<variant> merge concatenates, concat joins
<variant> Both do the same thing
<variant> merge deletes duplicates, concat does not
<question> How can you reorder levels in a MultiIndex?
df.reorder_levels([1,0])
<variantright> Switches the positions of the levels
<variant> Sorts the index
<variant> Drops a level
<variant> Creates a new column
<question2>What is the key difference between reorder_levels() and swaplevel() in hierarchical
indexing?
<variant>reorder_levels() allows arbitrary reordering of index levels, while swaplevel() only swaps
two levels
<variant>swaplevel() can reorder multiple levels, while reorder_levels() swaps levels
<variant>reorder_levels() can be used on non-hierarchical indexes, while swaplevel() cannot
<variant>swaplevel() requires specifying all levels, while reorder_levels() defaults to the first two
<question2>In a merge() operation, what does the how='outer' parameter do?
<variant>Performs a union of the keys from both DataFrames, including all rows from both
<variant>Includes only rows with keys present in both DataFrames
<variant>Includes rows from the left DataFrame only
<variant>Includes rows from the right DataFrame only
<question> Output of this code?
import pandas as pd
arrays = [['A','A','B','B'], [1,2,1,2]]
index = [Link].from_arrays(arrays, names=('letter','num'))
df = [Link]({'val':[10,20,30,40]}, index=index)
[Link]['A']
<variantright> Selects all rows where first level of MultiIndex is 'A'
<variant> Selects rows where second level is 'A'
<variant> Returns columns named 'A'
<variant> Produces an error
<question> Output of this code?
import pandas as pd
df = [Link]({'id':[1,1,2,2],'variable':
['X','Y','X','Y'],'value':[10,20,30,40]})
[Link](index='id', columns='variable', values='value')
<variantright> Reshapes from long to wide format with 'id' as index
<variant> Reshapes from wide to long
<variant> Drops column 'value'
<variant> Produces an error
Lecture 8. Visualizations and plotting
<question> How do you rotate y-axis tick labels?
[Link](rotation=90)
<variantright> Rotates y-axis labels by 90 degrees
<variant> Rotates x-axis
<variant> Rotates plot
<variant> Produces an error
<question> How do you change bar width in a bar plot?
df['A'].value_counts().[Link](width=0.3)
<variantright> Sets bar width to 0.3
<variant> Sets spacing
<variant> Changes color
<variant> Produces an error
<question> How do you plot a histogram with normalized frequencies?
df['A'].[Link](density=True)
<variantright> Plots histogram normalized to form a probability density
<variant> Plots raw counts
<variant> Plots line plot
<variant> Produces an error
<question>Which parameters control the spacing between subplots in matplotlib?
<variant>wspace and hspace
<variant>width_space and height_space
<variant> width_space and height_space
<variant>padding_x and padding_y
<question>What is the default behavior for connecting points in a matplotlib line plot?
<variant>Linear interpolation
<variant>Cubic interpolation
<variant>Step-wise connection
<variant>No connection
<question>Which function is used to set the x-axis label in matplotlib?
<variant>set_xlabel()
<variant>set_xlim()
<variant>set_xticks()
<variant>set_title()
<question>Which function is used to create a legend in a plot?
<variant>[Link]()
<variant>plt.show_legend()
<variant>plt.add_legend()
<variant>plt.legend_box()
<question2>How can you customize the row and column variables in a seaborn FacetGrid?
<variant>Pass them to the row and col parameters of [Link]()
<variant>Set them using grid.set_rows() and grid.set_cols()
<variant>Define them in the facet_vars parameter of FacetGrid()
<variant>Use the rows and columns parameters in FacetGrid()
Lecture 9. Grouping and Aggregation
<question>What happens to missing values in a group key during a GroupBy operation?
<variant>They are excluded from the result
<variant>They are replaced with zeros
<variant>They are included as a separate group
<variant>An error is raised
<question>When grouping by multiple keys, what is the type of the first element in the group
tuple?
<variant>A tuple of key values
<variant>A single key value
<variant>A pandas DataFrame
<variant>A list of grouped rows
<question>What does grouping by a dictionary in pandas achieve?
<variant>Maps specific values to group names
<variant>Creates hierarchical groups
<variant>Applies multiple aggregation functions
<variant>Splits groups by index levels
<question>What does the GroupBy object return when iterated over?
<variant>Tuples containing the group key and group data
<variant>Only the group key
<variant>Only the group data
<variant>Lists of grouped rows
<question> How do you apply different aggregations to different columns?
[Link]('Category').agg({'Value':'sum','Score':'max'})
<variantright> Aggregates Value by sum and Score by max per group
<variant> Aggregates all by sum
<variant> Aggregates all by max
<variant> Produces an error
<question> How do you pivot with multiple index and columns?
pd.pivot_table(df, index=['Category','SubCategory'],
columns='Region', values='Value', aggfunc='sum')
<variantright> Creates hierarchical index and columns, aggregating sum
<variant> Creates flat index
<variant> Drops Region
<variant> Produces an error
<question> How do you count occurrences in crosstab?
[Link](df['Category'], df['SubCategory'])
<variantright> Counts frequency of each Category/SubCategory combination
<variant> Sums values
<variant> Computes mean
<variant> Produces an error
<question> How do you count unique values per group?
[Link]('Category')['SubCategory'].nunique()
<variantright> Returns number of unique SubCategory values per Category
<variant> Returns total count
<variant> Returns mean
<variant> Produces an error
<question> Output of this code?
[Link]('Category')['Value'].agg(['sum','count','mean'])
<variantright> Returns sum, count, and mean for each category
<variant> Returns sum only
<variant> Returns mean only
<variant> Produces an error
<question> What does this code produce?
import pandas as pd
df = [Link]({'Category':['A','B','A','B'],'Value':
[10,20,30,40]})
[Link]('Category').sum()
<variantright> Sums 'Value' for each category
<variant> Counts rows per category
<variant> Averages 'Value' per category
<variant> Produces an error
<question> How do you apply multiple aggregations and rename columns?
[Link]('Category')['Value'].agg(Total='sum', Average='mean')
<variantright> Returns grouped aggregation with renamed columns
<variant> Produces error in older pandas versions
<variant> Aggregates sum only
<variant> Aggregates mean only
Lecture 10. Time Series
<question2>What will pd.to_datetime(["2018-02-29"]) return?
<variant>A ValueError due to an invalid date
<variant>NaT for the invalid date
<variant>A datetime object representing February 28, 2018
<variant>An empty DataFrame
<question2>When assembling datetime objects using pd.to_datetime(df), what happens if a column
is missing (e.g., "hour")?
<variant>The missing column is filled with default values (e.g., 0 for hours)
<variant>An error is raised due to the missing column
<variant>The operation skips rows with missing columns
<variant>The DataFrame is converted without the missing field
<question2>Which parameter in pd.to_datetime() allows you to set the timezone of the resulting
datetime objects?
<variant>utc
<variant>tz
<variant>timezone
<variant>localize
<question>What happens if the freq="infer" parameter fails to determine a consistent frequency?
<variant>A ValueError is raised
<variant>The index is created without a frequency
<variant>The freq parameter defaults to daily
<variant>A warning is issued
<question>Which format string correctly parses "12-11-2010 00:00"?
<variant>"%d-%m-%Y %H:%M"
<variant>"%Y-%m-%d %H:%M"
<variant>"%d/%m/%Y %H:%M"
<variant>"%m-%d-%Y %H:%M"
<question>What does the freq="M" parameter specify in pd.date_range()?
<variant>Monthly frequency
<variant>Minute-based frequency
<variant>Monday-based weekly frequency
<variant>Milliseconds frequency
<question>Which method converts a pandas period series back to timestamps?
<variant>to_timestamp()
<variant>to_period()
<variant>to_datetime()
<variant>to_dates()
<question> How do you forward-fill missing timestamps after resampling?
[Link]('H').ffill()
<variantright> Fills NaNs using previous available value
<variant> Fills with zero
<variant> Drops missing
<variant> Produces error
<question> How do you compute rolling correlation between two series?
df['value'].rolling(5).corr(df['other'])
<variantright> Returns rolling correlation over 5-row window
<variant> Returns covariance
<variant> Returns sum
<variant> Produces error
<question> How do you shift values using a time offset?
df['value'].shift(freq=[Link](days=3))
<variantright> Shifts values 3 days along the datetime index
<variant> Shifts by 3 rows
<variant> Drops rows
<variant> Produces error
<question> How do you create a business day date range?
pd.date_range('2020-01-01','2020-01-10', freq='B')
<variantright> Returns dates skipping weekends
<variant> Returns all days
<variant> Returns only weekends
<variant> Produces error
<question> How do you shift dates with month-end offset?
[Link] + [Link]()
<variantright> Shifts each date to the end of month
<variant> Shifts to month start
<variant> Produces error
<variant> Drops index
<question> How do you shift by custom business days?
[Link] + [Link](5)
<variantright> Moves index 5 business days forward
<variant> Moves 5 calendar days
<variant> Produces error
<variant> Shifts values
<question> How do you backward-fill missing timestamps after upsampling?
[Link]('H').bfill()
<variantright> Fills NaNs using next valid value
<variant> Fills with zero
<variant> Drops rows
<variant> Produces an error
<question> How do you shift values by 2 periods with shift?
df['value'].shift(2)
<variantright> Moves values down 2 rows
<variant> Shifts index
<variant> Drops rows
<variant> Produces an error
s = [Link]([1,2,3], index=pd.date_range('2023-01-01',
periods=3))
[Link](2, min_periods=1).sum()
<variantright> 2023-01-01 1.0 2023-01-02 3.0 2023-01-03 5.0 dtype: float64
<variant> 2023-01-01 NaN 2023-01-02 3 2023-01-03 5 dtype: float64
<variant> 2023-01-01 1 2023-01-02 2 2023-01-03 3 dtype: int64
<variant> Produces an error
<question> What will be the output?
df = [Link]({'value':[1,2,3]}, index=pd.period_range('2023-
01','2023-03', freq='M'))
[Link].to_timestamp()
<variantright> 2023-01-01 1 2023-02-01 2 2023-03-01 3 Freq: MS, Name:
value, dtype: int64
<variant> 2023-01-31 1 2023-02-28 2 2023-03-31 3 dtype: int64
<variant> Produces NaNs
<variant> Produces an error
<question> What will be the output?
s = [Link]([10,20,30], index=pd.date_range('2023-01-01',
periods=3))
[Link](span=2).mean()
<variantright> 2023-01-01 10.000000 2023-01-02 16.666667 2023-01-03
26.666667 dtype: float64
<variant> 2023-01-01 10 2023-01-02 20 2023-01-03 30 dtype: int64
<variant> 2023-01-01 10 2023-01-02 15 2023-01-03 25 dtype: int64
<variant> Produces an error
<question>Which of the following is a valid input for constructing a [Link]?
<variant>A list of ISO-8601 date strings
<variant>A dictionary of date strings
<variant>An integer index
<variant>A set of strings
<question> How do you convert a column to datetime in pandas?
df['date'] = pd.to_datetime(df['date'])
<variantright> Converts the column 'date' to datetime objects
<variant> Converts column to string
<variant> Converts to numeric
<variant> Produces an error
<question> How do you set a datetime column as index?
df.set_index('date', inplace=True)
<variantright> Sets 'date' column as index
<variant> Drops the column
<variant> Converts index to numeric
<variant> Produces an error
Lecture 12. Advanced pandas
<question> Output of this code?
df = [Link]({'A':[1,2,3],'B':[4,5,6]})
[Link](lambda x: x**2)
<variantright> A B 0 1 16 1 4 25 2 9 36
<variant> A B 0 1 4 1 2 5 2 3 6
<variant> Produces error
<question> Output of this code?
df = [Link]({'A':[1,2,3]})
[Link](lambda x: x*3)
<variantright> A 0 3 1 6 2 9
<variant> A 0 1 1 2 2 3
<variant> Produces error
<variant> Returns a Series
<question> What does transform return?
<variantright> Same shape as input DataFrame or Series
<variant> Always a single value per column
<variant> Always a single scalar
<variant> Produces error
<question> What happens if you use map on a DataFrame?
<variantright> Produces an error; map works on Series
<variant> Applies to all elements
<variant> Applies only to first column
<variant> Converts DataFrame to Series
<question> How do you convert a column to categorical?
df['col'] = df['col'].astype('category')
<variantright> Converts the column to categorical type
<variant> Converts to string
<variant> Converts to numeric
<variant> Produces an error
Lecture 13. Statistics and practical questions
<question> What is z-score?
<variantright> Number of standard deviations a value is from the mean
<variant> Difference between median and mean
<variant> Ratio of max to min
<variant> Range of data
<question> Output of this code?
from [Link] import zscore
import pandas as pd
s = [Link]([1,2,3,4,5])
zscore(s)
<variantright> array([-1.41421356, -0.70710678, 0., 0.70710678, 1.41421356])
<variant> array([1,2,3,4,5])
<variant> array([0,0,0,0,0])
<variant> Produces error
<question> What will be the output of this code?
import pandas as pd
import numpy as np
df = [Link]({'A':[1,2,3,4,5], 'B':[5,4,3,2,1]})
[Link](method='kendall')
<variantright> A B A 1.0 -1.0 B -1.0 1.0
<variant> A B A 1.0 1.0 B 1.0 1.0
<variant> Produces error
<variant> A B A 0.5 -0.5 B -0.5 0.5
<question> What will be the output of this code?
s = [Link]([1,2,2,3,3,3,4,4,4,4])
s.value_counts(normalize=True)
<variantright> 4 0.4 3 0.3 2 0.2 1 0.1 dtype: float64
<variant> 4 4 3 3 2 2 1 1 dtype: int64
<variant> Produces error
<variant> 1 0.1 2 0.2 3 0.3 4 0.4
<question> Output of this code?
s = [Link]([1,2,3,4,5])
[Link]((s - [Link]())**2)
<variantright> Series of cumulative squared deviations
<variant> Series of cumulative sums
<variant> Series of cumulative means
<variant> Produces error
<question> What does this code compute?
df = [Link]({'X':[1,2,3,4,5], 'Y':[5,4,3,2,1]})
([Link]() - [Link]())/[Link]()
<variantright> Standardized ranks of each column
<variant> Z-scores of original values
<variant> Normalized values between 0 and 1
<variant> Produces error
<question> What will be the output of this code?
import pandas as pd
import numpy as np
df = [Link]({
'date': pd.date_range('2023-01-01', periods=5),
'val': [1, [Link], 3, [Link], 5],
'cat': ['A','B','A','B','C']
})
df['val'] = df['val'].interpolate(method='linear')
[Link]('cat')['val'].mean()
<variantright> cat A 2.0 B 3.0 C 5.0 Name: val, dtype: float64
<variant> cat A 2.0 B 2.0 C 5.0 Name: val, dtype: float64
<variant> Produces error
<variant> Returns DataFrame instead of Series
<question> What does this code compute?
df['val'].rolling(2, min_periods=1).apply(lambda x: [Link](x))
<variantright> Rolling product of values over a 2-row window, computing even if only 1 value is
present
<variant> Rolling sum over 2 rows
<variant> Cumulative product
<variant> Produces error
<question> What is the output?
df['cat'] = df['cat'].astype('category')
df['cat'].[Link]
<variantright> 0 0 1 1 2 0 3 1 4 2 dtype: int8
<variant> Produces error
<variant> Returns original values
<variant> Returns strings of categories
<question> What is the result of this multi-step operation?
df['date'] = pd.to_datetime(df['date'])
df.set_index('date', inplace=True)
[Link]('2D')['val'].sum()
<variantright>
date
2023-01-01 3.0
2023-01-03 3.0
2023-01-05 5.0
Freq: 2D, Name: val, dtype: float64
<variant> Produces error
<variant> Returns cumulative sum instead
<variant> Returns original daily values
<question> Output of this code?
df['val_z'] = (df['val'] - df['val'].mean()) / df['val'].std()
[Link]('cat')['val_z'].mean()
<variantright> cat A 0.0 B 0.0 C 0.0 Name: val_z, dtype: float64
<variant> Produces error
<variant> Returns original val
<variant> Non-zero values