## Evaluator Report

Sort By:
Student:
Roll:
File:

### Nitin Sahsani — 2423350

File: 2423350_Nitin.Sahsani (2).ipynb

Total: 27/58 (46.55%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Series' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Score' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_40>", line 2, in advanced_filter_and_create File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Score'

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 2, in clean_age_data File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 7316, in fillna value, method = validate_fillna_kwargs(value, method) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/util/_validators.py", line 293, in validate_fillna_kwargs raise ValueError("Must specify a fill 'value' or 'method'.") ValueError: Must specify a fill 'value' or 'method'.

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'method' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'method' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'method' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | passed | 1 |
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | passed | 1 |
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | passed | 1 |

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 2, in fill_missing_with_mean File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 5055, in select_dtypes raise ValueError("at least one of include or exclude must be nonempty") ValueError: at least one of include or exclude must be nonempty

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert list(result['Name']) == ['B', 'D'] | passed | 1 |
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | passed | 1 |

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Arun Murari Gottipati — 2423360

File: ArunMG(2423360).ipynb

Total: 2/58 (3.45%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 3, in clean_age_data File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 11733, in median result = super().median(axis, skipna, numeric_only, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 12496, in median return self._stat_function( ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 12442, in _stat_function return self._reduce( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 11589, in _reduce res = df._mgr.reduce(blk_func) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/internals/managers.py", line 1519, in reduce nbs = blk.reduce(func) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/internals/blocks.py", line 406, in reduce result = func(self.values) ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 11508, in blk_func return op(values, axis=axis, skipna=skipna, **kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/nanops.py", line 147, in f result = alt(values, axis=axis, skipna=skipna, **kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/nanops.py", line 787, in nanmedian raise TypeError(f"Cannot convert {values} to numeric") TypeError: Cannot convert [['Alice' 'Bob' 'Charlie' 'Diana' 'Eve']] to numeric

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 3, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'drop_rows_with_nan' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 3, in fill_missing_with_mean NameError: name 'NaN' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_36>", line 3, in get_summary_stats File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 11720, in mean result = super().mean(axis, skipna, numeric_only, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 12485, in mean return self._stat_function( ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 12442, in _stat_function return self._reduce( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 11589, in _reduce res = df._mgr.reduce(blk_func) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/internals/managers.py", line 1519, in reduce nbs = blk.reduce(func) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/internals/blocks.py", line 406, in reduce result = func(self.values) ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 11508, in blk_func return op(values, axis=axis, skipna=skipna, **kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/nanops.py", line 147, in f result = alt(values, axis=axis, skipna=skipna, **kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/nanops.py", line 404, in new_func result = func(values, axis=axis, skipna=skipna, mask=mask, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/nanops.py", line 720, in nanmean the_sum = _ensure_numeric(the_sum) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/nanops.py", line 1686, in _ensure_numeric raise TypeError(f"Could not convert {x} to numeric") TypeError: Could not convert ['AliceBobAliceCharlie' 'XYXZ'] to numeric

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_22>", line 3, in group_by_mean NameError: name 'group_column' is not defined

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

### Harsh Mittal — 2423373

File: Harsh CIA.ipynb

Total: 9/58 (15.52%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'describe_numeric' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### Mayur garg — 2423358

File: MAYUR 2423358 (1).ipynb

Total: 29/58 (50.0%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'add_updated_salary' is not defined

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'advanced_filter_and_create' is not defined

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | passed | 1 |
assert (result['Age'] <= 100).all() # No outliers | passed | 1 |
assert result.shape[0] == 4 # Charlie (105) removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | passed | 1 |

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: 'function' object has no attribute 'reset_index'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'fill_missing_college' is not defined

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert list(result['Name']) == ['B', 'D'] | passed | 1 |
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | passed | 1 |

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> TypeError: cannot unpack non-iterable NoneType object

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'merge_dataframes' is not defined

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

### NISHANT KUMAR — 2423349

File: Nishant_Kumar(2423349).ipynb

Total: 12/58 (20.69%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_16>", line 2, in count_missing_values TypeError: Series.isnull() missing 1 required positional argument: 'self'

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'describe_numeric' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 4, in drop_rows_with_nan AttributeError: 'function' object has no attribute 'reset_index'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college AttributeError: 'list' object has no attribute 'fillna'

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 3, in fill_missing_with_mean UnboundLocalError: cannot access local variable 'fill_missing_with_mean' where it is not associated with a value

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'filter_profit_range' is not defined

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'group_by_mean' is not defined

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Sarthak Chaudhary — 2423346

File: Sarthak_Chaudhary_2423346.ipynb

Total: 29/58 (50.0%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | passed | 1 |
assert result['UpdatedSalary'].iloc[0] == 52500 | passed | 1 |
assert result['UpdatedSalary'].iloc[1] == 57750 | passed | 1 |

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 3, in clean_age_data File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 5603, in drop return super().drop( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 4810, in drop obj = obj._drop_axis(labels, axis, level=level, errors=errors) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 4852, in _drop_axis new_axis = axis.drop(labels, errors=errors) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 7136, in drop raise KeyError(f"{labels[mask].tolist()} not found in axis") KeyError: '[True] not found in axis'

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_16>", line 2, in count_missing_values File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'insull'

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | passed | 1 |
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'College'
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'College'

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'val' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'val'
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'val' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'val'

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_34>", line 2, in filter_profit_range TypeError: Series.between() missing 1 required positional argument: 'right'

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'category'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'category'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_12>", line 2, in select_column File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'series'

### Soham Uday Sahasrabudhe — 2423363

File: SohamUdaySahasrabudhe2423363.ipynb

Total: 12/58 (20.69%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'clean_age_data' is not defined

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'describe_numeric' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: module 'pandas' has no attribute 'dopna'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'fill_missing_with_mean' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'group_by_mean' is not defined

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### student name — student roll number

File: Untitled.ipynb

Total: 0/58 (0.0%)

Question: _identity_check_
Student did not customize name/roll_number.

Assertion | Status | Score | Error
--- | --- | --- | ---
[missing student identity] | failed | 0 | Student notebook missing personalized name/roll_number. Please define: name = 'Your Name' roll_number = 'Your Roll Number'

### Urvi Kamble — 2423383

File: Urvi Kamble.ipynb

Total: 9/58 (15.52%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'count' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college NameError: name 'df_copy' is not defined

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_6>", line 2, in get_dataframe_info File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'to_list'

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_22>", line 2, in group_by_mean NameError: name 'agg' is not defined

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Vaishnavi Santosh Kavishetti — 2423381

File: Vaishnavi Kavishetti 2423381 (1).ipynb

Total: 9/58 (15.52%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'clean_age_data' is not defined

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_28>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'count' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_30>", line 3, in drop_duplicates_by_cols NameError: name 'data' is not defined

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_7>", line 2, in get_dataframe_info File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'to_list'

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Vansh Rohida — 2423372

File: VanshRohida2423372 (1).ipynb

Total: 16/58 (27.59%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_16>", line 2, in count_missing_values File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'insull'

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: module 'pandas' has no attribute 'dropna'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'fill_missing_with_mean' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_12>", line 2, in select_column NameError: name 'threshold' is not defined

### RohanGM — 2423364

File: rohan_64.ipynb

Total: 12/58 (20.69%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'add_updated_salary' is not defined

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'count' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college NameError: name 'df_copy' is not defined

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_6>", line 2, in get_dataframe_info File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'to_list'

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | passed | 1 |
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | passed | 1 |

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Kanishka_Singh — 2423376

File: student_notebook (1) (1).ipynb

Total: 14/58 (24.14%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Age' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 2, in clean_age_data File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Age'

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 3, in convert_to_datetime NameError: name 'datetime' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_16>", line 3, in count_missing_values File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'insull'

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'count' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: ('Name', 'Team') The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_28>", line 2, in drop_duplicates_by_cols File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: ('Name', 'Team')

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | passed | 1 |
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Unknown' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Unknown'

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 3, in fill_missing_with_mean File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 5055, in select_dtypes raise ValueError("at least one of include or exclude must be nonempty") ValueError: at least one of include or exclude must be nonempty

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_14>", line 3, in filter_by_threshold TypeError: NDFrame.filter() got an unexpected keyword argument 'column'

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Profit' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_34>", line 2, in filter_profit_range File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Profit'

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: ('Age', 'Salary') The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_36>", line 2, in get_summary_stats File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: ('Age', 'Salary')

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'category' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'category'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'category' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'category'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Johann Karl — 2423382

File: student_notebook (1)(1).ipynb

Total: 33/58 (56.9%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Series' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Score' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_40>", line 2, in advanced_filter_and_create File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Score'

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 2, in clean_age_data File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 7316, in fillna value, method = validate_fillna_kwargs(value, method) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/util/_validators.py", line 293, in validate_fillna_kwargs raise ValueError("Must specify a fill 'value' or 'method'.") ValueError: Must specify a fill 'value' or 'method'.

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | passed | 1 |
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | passed | 1 |
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | passed | 1 |

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'fill_missing_with_mean' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert list(result['Name']) == ['B', 'D'] | passed | 1 |
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | passed | 1 |

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_36>", line 2, in get_summary_stats NameError: name 'pa' is not defined

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | passed | 1 |
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | passed | 1 |

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### vikram sinha — 2423359

File: student_notebook (1)(10).ipynb

Total: 0/58 (0.0%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_32>", line 3, in add_updated_salary TypeError: 'DataFrame' object is not callable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'clean_age_data' is not defined

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'convert_to_datetime' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'describe_numeric' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_28>", line 2, in drop_duplicates_by_cols File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'drop_duplicate'

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'drop_rows_with_nan' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'fill_missing_college' is not defined

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'fill_missing_with_mean' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert filtered['score'].min() > 80 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'filter_profit_range' is not defined

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_6>", line 2, in get_dataframe_info AttributeError: 'NoneType' object has no attribute 'shape'

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'get_first_n_rows' is not defined

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'get_summary_stats' is not defined

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'group_by_mean' is not defined

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 8, in <module> File "<student_cell_38>", line 3, in groupby_team_agg TypeError: 'DataFrame' object is not callable

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert list(df.columns) == ['name', 'age', 'score'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert df.shape == (3, 3) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'merge_dataframes' is not defined

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### student name — student roll number

File: student_notebook (1)(11).ipynb

Total: 0/58 (0.0%)

Question: _identity_check_
Student did not customize name/roll_number.

Assertion | Status | Score | Error
--- | --- | --- | ---
[missing student identity] | failed | 0 | Student notebook missing personalized name/roll_number. Please define: name = 'Your Name' roll_number = 'Your Roll Number'

### Kushagra Gulati — 2423347

File: student_notebook (1)(2).ipynb

Total: 33/58 (56.9%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Series' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Score' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_40>", line 2, in advanced_filter_and_create File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Score'

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 2, in clean_age_data File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 7316, in fillna value, method = validate_fillna_kwargs(value, method) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/util/_validators.py", line 293, in validate_fillna_kwargs raise ValueError("Must specify a fill 'value' or 'method'.") ValueError: Must specify a fill 'value' or 'method'.

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | passed | 1 |
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | passed | 1 |
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | passed | 1 |

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 2, in fill_missing_with_mean File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 5055, in select_dtypes raise ValueError("at least one of include or exclude must be nonempty") ValueError: at least one of include or exclude must be nonempty

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert list(result['Name']) == ['B', 'D'] | passed | 1 |
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | passed | 1 |

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | passed | 1 |
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | passed | 1 |

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Udit Baid — 2423384

File: student_notebook (1)(3).ipynb

Total: 26/58 (44.83%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Series' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Score' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_40>", line 2, in advanced_filter_and_create File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Score'

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 2, in clean_age_data File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 7316, in fillna value, method = validate_fillna_kwargs(value, method) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/util/_validators.py", line 293, in validate_fillna_kwargs raise ValueError("Must specify a fill 'value' or 'method'.") ValueError: Must specify a fill 'value' or 'method'.

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'resest_index'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | passed | 1 |
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 2, in fill_missing_with_mean File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 5055, in select_dtypes raise ValueError("at least one of include or exclude must be nonempty") ValueError: at least one of include or exclude must be nonempty

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_34>", line 2, in filter_profit_range File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 1580, in __nonzero__ raise ValueError( ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'function' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'function' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'function' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | passed | 1 |
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | passed | 1 |

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Aakarsh Jawa — 2423380

File: student_notebook (1)(4).ipynb

Total: 18/58 (31.03%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_16>", line 2, in count_missing_values File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'isnu11'

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan NameError: name 'true' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'fill_missing_with_mean' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_22>", line 2, in group_by_mean AttributeError: 'str' object has no attribute 'mean'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

### ANIRUDDHAN R M — 2423353

File: student_notebook (1)(5).ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'advanced_filter_and_create' is not defined

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> File "<student_cell_4>", line 2, in load_csv_string AttributeError: 'str' object has no attribute 'to_dataframe'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'drop_rows_with_nan' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | passed | 1 |
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | passed | 1 |

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 2, in fill_missing_with_mean AttributeError: 'Index' object has no attribute 'select_dtypes'

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> File "<student_cell_4>", line 2, in load_csv_string AttributeError: 'str' object has no attribute 'to_dataframe'

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert list(result['Name']) == ['B', 'D'] | passed | 1 |
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | passed | 1 |

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> File "<student_cell_4>", line 2, in load_csv_string AttributeError: 'str' object has no attribute 'to_dataframe'

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> File "<student_cell_4>", line 2, in load_csv_string AttributeError: 'str' object has no attribute 'to_dataframe'

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'group_by_mean' is not defined

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'AvgSalary' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1185, in __getitem__ return self._getitem_tuple(key) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1369, in _getitem_tuple return self._getitem_lowerdim(tup) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1066, in _getitem_lowerdim section = self._getitem_axis(key, axis=i) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1432, in _getitem_axis return self._get_label(key, axis=axis) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1382, in _get_label return self.obj.xs(label, axis=axis) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 4309, in xs return self[key] ~~~~^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'AvgSalary'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'TotalProfit' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1185, in __getitem__ return self._getitem_tuple(key) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1369, in _getitem_tuple return self._getitem_lowerdim(tup) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1066, in _getitem_lowerdim section = self._getitem_axis(key, axis=i) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1432, in _getitem_axis return self._get_label(key, axis=axis) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexing.py", line 1382, in _get_label return self.obj.xs(label, axis=axis) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 4309, in xs return self[key] ~~~~^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'TotalProfit'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> File "<student_cell_4>", line 2, in load_csv_string AttributeError: 'str' object has no attribute 'to_dataframe'

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> File "<student_cell_4>", line 2, in load_csv_string AttributeError: 'str' object has no attribute 'to_dataframe'

### aahaan chatterjee — 2423354

File: student_notebook (1)(6).ipynb

Total: 25/58 (43.1%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Series' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | passed | 1 |
assert result['UpdatedSalary'].iloc[1] == 57750 | passed | 1 |

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_40>", line 2, in advanced_filter_and_create TypeError: unsupported operand type(s) for >>: 'list' and 'int'

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'convert_to_datetime' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_10>", line 2, in describe_numeric TypeError: NDFrame.describe() missing 1 required positional argument: 'self'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | passed | 1 |
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | passed | 1 |
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | passed | 1 |

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'filter_by_threshold' is not defined

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_34>", line 2, in filter_profit_range File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 1580, in __nonzero__ raise ValueError( ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'get_dataframe_info' is not defined

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'get_first_n_rows' is not defined

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | passed | 1 |
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | passed | 1 |

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_12>", line 2, in select_column AttributeError: module 'pandas' has no attribute 'series'

### Siva Samvit Vemuri — 2423348

File: student_notebook (1)(7).ipynb

Total: 1/58 (1.72%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'add_updated_salary' is not defined

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 2, in clean_age_data NameError: name 'sample_df' is not defined

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'convert_to_datetime' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_16>", line 2, in count_missing_values File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'insull'

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'drop_duplicates_by_cols' is not defined

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'drop_rows_with_nan' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'fill_missing_college' is not defined

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 2, in fill_missing_with_mean File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 5055, in select_dtypes raise ValueError("at least one of include or exclude must be nonempty") ValueError: at least one of include or exclude must be nonempty

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'filter_profit_range' is not defined

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_36>", line 2, in get_summary_stats NameError: name 'sample_df' is not defined

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'category' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'category'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'category' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'category'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 8, in <module> NameError: name 'groupby_team_agg' is not defined

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'merge_dataframes' is not defined

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

### Narane Karthic — 2423379

File: student_notebook (1)(8).ipynb

Total: 20/58 (34.48%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | passed | 1 |
assert result['UpdatedSalary'].iloc[0] == 52500 | passed | 1 |
assert result['UpdatedSalary'].iloc[1] == 57750 | passed | 1 |

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'datetime' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 1580, in __nonzero__ raise ValueError( ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 1580, in __nonzero__ raise ValueError( ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 1580, in __nonzero__ raise ValueError( ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'drop_duplicates_by_cols' is not defined

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college NameError: name 'college' is not defined

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 2, in fill_missing_with_mean File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 7316, in fillna value, method = validate_fillna_kwargs(value, method) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/util/_validators.py", line 293, in validate_fillna_kwargs raise ValueError("Must specify a fill 'value' or 'method'.") ValueError: Must specify a fill 'value' or 'method'.

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'Name'
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'Profit'

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_24>", line 3, in merge_dataframes NameError: name 'df' is not defined

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_12>", line 2, in select_column File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'series'

### S.Vaigunda Ram Singh — 2423345

File: student_notebook (1)(9).ipynb

Total: 33/58 (56.9%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | passed | 1 |
assert result['UpdatedSalary'].iloc[0] == 52500 | passed | 1 |
assert result['UpdatedSalary'].iloc[1] == 57750 | passed | 1 |

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'datetime' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | passed | 1 |

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | passed | 1 |
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'College'
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'College'

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'val' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'val'
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'val' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'val'

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'Name'
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'Profit'

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'category'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'category'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Team' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Team'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_12>", line 2, in select_column File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'series'

### devansh grover — 2423366

File: student_notebook (1).ipynb

Total: 12/58 (20.69%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Age' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_43>", line 2, in advanced_filter_and_create File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'Age'

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_29>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_11>", line 2, in describe_numeric TypeError: NDFrame.describe() got an unexpected keyword argument 'includes'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_31>", line 2, in drop_duplicates_by_cols File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'drop_duplicate'

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'drop_rows_with_nan' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_25>", line 2, in group_by_mean NameError: name 'left' is not defined

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### Farhan Aziz — 2423377

File: student_notebook (1)2423377.ipynb

Total: 9/58 (15.52%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'advanced_filter_and_create' is not defined

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'clean_age_data' is not defined

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_28>", line 2, in drop_duplicates_by_cols File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 6840, in drop_duplicates result = self[-self.duplicated(subset, keep=keep)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 6972, in duplicated raise KeyError(Index(diff)) KeyError: Index(['team'], dtype='object')

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: 'function' object has no attribute 'reset_index'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'fillna9'

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'filter_profit_range' is not defined

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

### student name — student roll number

File: student_notebook (2)(1).ipynb

Total: 0/58 (0.0%)

Question: _identity_check_
Student did not customize name/roll_number.

Assertion | Status | Score | Error
--- | --- | --- | ---
[missing student identity] | failed | 0 | Student notebook missing personalized name/roll_number. Please define: name = 'Your Name' roll_number = 'Your Roll Number'

### Deshpande Rugved Shirish — 2423370

File: student_notebook (2).ipynb

Total: 26/58 (44.83%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'advanced_filter_and_create' is not defined

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | passed | 1 |
assert (result['Age'] <= 100).all() # No outliers | passed | 1 |
assert result.shape[0] == 4 # Charlie (105) removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | passed | 1 |

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_28>", line 2, in drop_duplicates_by_cols File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 6840, in drop_duplicates result = self[-self.duplicated(subset, keep=keep)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 6972, in duplicated raise KeyError(Index(diff)) KeyError: Index(['team'], dtype='object')

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: 'function' object has no attribute 'reset_index'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'fillna9'

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'filter_profit_range' is not defined

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

### Tejas Pandey — 2423352

File: student_notebook (3)(1).ipynb

Total: 21/58 (36.21%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Series' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan NameError: name 'true' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'fill_missing_with_mean' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_22>", line 2, in group_by_mean AttributeError: 'str' object has no attribute 'mean'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

### shaurya — 2423374

File: student_notebook (3)(2).ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### shaurya — 2423374

File: student_notebook (3)(3).ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### shaurya — 2423374

File: student_notebook (3)(4).ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### shaurya — 2423374

File: student_notebook (3)(5).ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### Deshpande Rugved Shirish — 2423370

File: student_notebook (3).ipynb

Total: 26/58 (44.83%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'advanced_filter_and_create' is not defined

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | passed | 1 |
assert (result['Age'] <= 100).all() # No outliers | passed | 1 |
assert result.shape[0] == 4 # Charlie (105) removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | passed | 1 |

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_28>", line 2, in drop_duplicates_by_cols File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 6840, in drop_duplicates result = self[-self.duplicated(subset, keep=keep)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 6972, in duplicated raise KeyError(Index(diff)) KeyError: Index(['team'], dtype='object')

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: 'function' object has no attribute 'reset_index'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'fillna9'

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'filter_profit_range' is not defined

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

### shaurya — 2423374

File: student_notebook (4)(1).ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### Divit vats — 2423355

File: student_notebook (4)(2).ipynb

Total: 18/58 (31.03%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'advanced_filter_and_create' is not defined

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'clean_age_data' is not defined

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_16>", line 2, in count_missing_values AttributeError: 'function' object has no attribute 'sum'

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: module 'pandas' has no attribute 'dropna'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

### shaurya — 2423374

File: student_notebook (4).ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### Nimrat Singh — 2423361

File: student_notebook Nimrat Singh (3).ipynb

Total: 29/58 (50.0%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'advanced_filter_and_create' is not defined

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | passed | 1 |
assert (result['Age'] <= 100).all() # No outliers | passed | 1 |
assert result.shape[0] == 4 # Charlie (105) removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | passed | 1 |

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_28>", line 2, in drop_duplicates_by_cols File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 6840, in drop_duplicates result = self[-self.duplicated(subset, keep=keep)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 6972, in duplicated raise KeyError(Index(diff)) KeyError: Index(['team'], dtype='object')

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: 'function' object has no attribute 'reset_index'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college TypeError: NDFrame.fillna() takes from 1 to 2 positional arguments but 3 were given

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 2, in fill_missing_with_mean NameError: name 'ret' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | passed | 1 |
assert list(result['Name']) == ['B', 'D'] | passed | 1 |
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | passed | 1 |

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |
assert stats.loc['count', 'Age'] == 4 | passed | 1 |

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

### Aradhya Mishra — 2423371

File: student_notebook(1)(1).ipynb

Total: 12/58 (20.69%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'describe_numeric' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'drop_rows_with_nan' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'fill_missing_with_mean' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> NameError: name 'get_summary_stats' is not defined

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'group_by_mean' is not defined

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_12>", line 2, in select_column NameError: name 'threshold' is not defined

### Ashmith B Shetty — 2423378

File: student_notebook(1)(2).ipynb

Total: 9/58 (15.52%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'count' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_28>", line 2, in drop_duplicates_by_cols NameError: name 'drop_duplicates' is not defined

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### devansh — 2423366

File: student_notebook(1).ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### Tejas Pandey — 2423352

File: student_notebook(2).ipynb

Total: 21/58 (36.21%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Series' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'UpdatedSalary'

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan NameError: name 'true' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'fill_missing_with_mean' is not defined

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_22>", line 2, in group_by_mean AttributeError: 'str' object has no attribute 'mean'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

### Ashmith B Shetty — 2423378

File: student_notebook(3).ipynb

Total: 9/58 (15.52%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'count' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> File "<student_cell_28>", line 2, in drop_duplicates_by_cols NameError: name 'drop_duplicates' is not defined

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### Kapil Rawat — 2423356

File: student_notebook(4).ipynb

Total: 16/58 (27.59%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | passed | 1 |
assert (result['Age'] <= 100).all() # No outliers | passed | 1 |
assert result.shape[0] == 4 # Charlie (105) removed | passed | 1 |
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | passed | 1 |

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['b'] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert missing['c'] == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'count' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### Sai_Shobhith — 2423351

File: student_notebook(5).ipynb

Total: 21/58 (36.21%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_42>", line 2, in clean_age_data NameError: name 'sample_df' is not defined

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'datetime' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 7, in <module> NameError: name 'drop_duplicates_by_cols' is not defined

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | passed | 1 |
assert clean_df['x'].iloc[0] == 1 | passed | 1 |
assert clean_df['y'].iloc[0] == 10 | passed | 1 |

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college NameError: name 'sample_df' is not defined

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_20>", line 2, in fill_missing_with_mean File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 5055, in select_dtypes raise ValueError("at least one of include or exclude must be nonempty") ValueError: at least one of include or exclude must be nonempty

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_14>", line 2, in filter_by_threshold TypeError: NDFrame.filter() got an unexpected keyword argument 'column'

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_34>", line 2, in filter_profit_range NameError: name 'sample_df' is not defined

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_36>", line 2, in get_summary_stats NameError: name 'sample_df' is not defined

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'category' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'category'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas/_libs/index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7096, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'category' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1133, in __getitem__ return self._get_value(key) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/series.py", line 1249, in _get_value loc = self.index.get_loc(label) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3819, in get_loc raise KeyError(key) from err KeyError: 'category'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 8, in <module> File "<student_cell_38>", line 2, in groupby_team_agg File "/usr/local/lib/python3.11/site-packages/pandas/core/generic.py", line 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'group'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert age_series.tolist() == [25, 30, 22] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'tolist'

### student name — student roll number

File: student_notebook(6).ipynb

Total: 0/58 (0.0%)

Question: _identity_check_
Student did not customize name/roll_number.

Assertion | Status | Score | Error
--- | --- | --- | ---
[missing student identity] | failed | 0 | Student notebook missing personalized name/roll_number. Please define: name = 'Your Name' roll_number = 'Your Roll Number'

### devansh — 2423366

File: student_notebook.ipynb

Total: 13/58 (22.41%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert clean_df.shape[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert clean_df['x'].iloc[0] == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert clean_df['y'].iloc[0] == 10 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert cols == 3 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert columns == ['x', 'y', 'z'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'select_column' is not defined

### Aarav Danani — 2423343

File: student_notebook2423343.ipynb

Total: 3/58 (5.17%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert pd.api.types.is_datetime64_any_dtype(converted['date']) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert converted['date'].iloc[0].year == 2023 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert converted['date'].iloc[0].month == 1 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert missing['a'] == 1 | passed | 1 |
assert missing['b'] == 2 | passed | 1 |
assert missing['c'] == 0 | passed | 1 |

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'drop_rows_with_nan' is not defined

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['College'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'merge_dataframes' is not defined

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 3, in <module> NameError: name 'load_csv_string' is not defined

### Lalit Mohan Kumar — 2423375

File: student_notebook_solved.ipynb

Total: 21/58 (36.21%)

Question: add_updated_salary
Given a DataFrame df with a 'Salary' column, write code to increase salary by 5% and store it in a new column 'UpdatedSalary'. **Hint:** Multiply the Salary column by 1.05 to increase by 5%. **Choose the correct code:** - (a) `df['UpdatedSalary'] = df['Salary'] * 5` - (b) `df['UpdatedSalary'] = df['Salary'] * 1.05` - (c) `df['UpdatedSalary'] = df['Salary'] + 0.05` - (d) `df['UpdatedSalary'] = df['Salary'].apply(lambda x: x * 5)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert 'UpdatedSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result['UpdatedSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['UpdatedSalary'].iloc[1] == 57750 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: advanced_filter_and_create
Given a DataFrame with columns: Name, Score1, Score2 Write Python code to: 1. Select only rows where Score1 > 40 AND Score2 > 50 2. Create a new column AverageScore = mean of Score1 and Score2 3. return dataframe with only the `[['Name', 'AverageScore']]` **Hint:** Filter first using boolean indexing, then add the new column, then select specific columns.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 # Only B and C qualify | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'C'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: clean_age_data
You have a DataFrame with an 'Age' column containing missing values and outliers (Age > 100). Write Python code to: 1. Replace missing values with the median age 2. Remove rows where Age > 100 3. Return the cleaned DataFrame **Hint:** Use `.fillna()` with median, then filter with boolean indexing.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result['Age'].isnull().sum() == 0 # No missing values | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert (result['Age'] <= 100).all() # No outliers | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert result.shape[0] == 4 # Charlie (105) removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: convert_to_datetime
**Return:** A DataFrame where the specified column has been converted to datetime **Choose the correct code:** - (a) `df_copy[col_name] = df_copy[col_name].astype(datetime)` - (b) `df_copy[col_name] = pd.to_datetime(df_copy[col_name])` - (c) `df_copy[col_name].convert_to_datetime()` - (d) `df_copy[col_name] = datetime.strptime(df_copy[col_name], '%Y-%m-%d')`

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_26>", line 2, in convert_to_datetime NameError: name 'df_copy' is not defined

Question: count_missing_values
**Return:** A pandas Series with column names as index and count of NaN as values **Hint:** Use `.isnull().sum()` to count missing values in each column.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> NameError: name 'count_missing_values' is not defined

Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | passed | 1 |
assert 'count' in stats.index | passed | 1 |
assert 'mean' in stats.index | passed | 1 |
assert 'std' in stats.index | passed | 1 |

Question: drop_duplicates_by_cols
You have a DataFrame with duplicate rows. The command `drop_duplicates` on subset of columns named `['Name', 'Team']` is to be used.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 3 # One duplicate removed | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: drop_rows_with_nan
**Return:** A DataFrame with all rows containing NaN removed **Hint:** Use `.dropna()` to remove rows with missing values, then `.reset_index(drop=True)` to renumber rows.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 4, in <module> File "<student_cell_18>", line 2, in drop_rows_with_nan AttributeError: module 'pandas' has no attribute 'dropna'

Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.

Assertion | Status | Score | Error
--- | --- | --- | ---
[context setup] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 26, in run_assertions exec(compile(context_code, "<context_code>", "exec"), ns) File "<context_code>", line 6, in <module> File "<student_cell_30>", line 2, in fill_missing_college NameError: name 'df_copy' is not defined

Question: fill_missing_with_mean
**Return:** A DataFrame where NaN values in numeric columns are replaced by column mean **Hint:** Get numeric columns using `.select_dtypes()`, then use `.fillna()` with the column mean.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filled['val'].isnull().sum() == 0 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert filled['val'].iloc[2] == 20 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: filter_by_threshold
**Return:** A DataFrame containing only rows where column > threshold **Hint:** Use boolean indexing `df[df[col_name] > threshold]` and `.reset_index(drop=True)` to reset row indices. **Choose the correct code:** - (a) `return df.filter(column=col_name, value=threshold)` - (b) `return df.loc[df[col_name] > threshold]` - (c) `return df[df[col_name] > threshold].reset_index(drop=True)` - (d) `return df.query(f'{col_name} > {threshold}')`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert filtered.shape[0] == 3 | passed | 1 |
assert filtered['score'].min() > 80 | passed | 1 |

Question: filter_profit_range
Write Python code to select rows where 'Profit' is between 30 and 55 (inclusive). **Hint:** Use boolean indexing with AND operator `&`.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert list(result['Name']) == ['B', 'D'] | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55)) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> TypeError: 'NoneType' object is not subscriptable

Question: get_dataframe_info
**Return:** A tuple of (number of rows, number of columns, list of column names) **Choose the correct code:** - (a) `return (df.size, df.ndim, df.columns)` - (b) `return (df.shape[0], df.shape[1], list(df.columns))` - (c) `return df.info()` - (d) `return (len(df), len(df.index), df.to_list())`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert rows == 2 | passed | 1 |
assert cols == 3 | passed | 1 |
assert columns == ['x', 'y', 'z'] | passed | 1 |

Question: get_first_n_rows
**Return:** DataFrame containing first n rows **Choose the correct code:** - (a) `return df.iloc[:n]` - (b) `return df.head(n)` - (c) `return df.nlargest(n, axis=0)` - (d) `return df[:n:1]`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert first_two.shape == (2, 2) | passed | 1 |
assert first_two['a'].tolist() == [1, 2] | passed | 1 |

Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(stats, pd.DataFrame) | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AssertionError
assert 'mean' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert 'std' in stats.index | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'index'
assert stats.loc['count', 'Age'] == 4 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: group_by_mean
**Return:** A DataFrame with grouped results (group column and mean) **Hint:** Use `.groupby(group_col)[agg_col].mean()` and `.reset_index()` to convert to DataFrame.

Assertion | Status | Score | Error
--- | --- | --- | ---
assert grouped.shape[0] == 2 | passed | 1 |
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20 | passed | 1 |
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30 | passed | 1 |

Question: groupby_team_agg
You have a DataFrame with columns: Name, Team, Salary, Profit Write Python code to: 1. Group the data by Team 2. aggregate average salary and total profit for each team 3. return the result **Hint:** Use `.groupby()` with `.agg()` for multiple aggregations. **Choose the correct code:** - (a) `df.groupby('Team').agg({'Salary': 'mean', 'Profit': 'sum'})` - (b) `df.groupby('Team')[['Salary', 'Profit']].agg(['mean', 'sum'])` - (c) `df.group('Team').apply(lambda x: {'avg_salary': x['Salary'].mean(), 'total_profit': x['Profit'].sum()})`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert result.shape[0] == 2 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'shape'
assert 'AvgSalary' in result.columns | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'columns'
assert result.loc[result['Team'] == 'X', 'AvgSalary'].iloc[0] == 52500 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'
assert result.loc[result['Team'] == 'X', 'TotalProfit'].iloc[0] == 75 | failed | 0 | Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.py", line 44, in run_assertions exec(compile(code, "<assertion>", "exec"), ns) File "<assertion>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'loc'

Question: load_csv_string
**Return:** A pandas DataFrame from the CSV string **Choose the correct line:** - (a) `return pd.read_excel(StringIO(csv_string))` - (b) `return pd.read_csv(StringIO(csv_string))` - (c) `return pd.DataFrame(csv_string.split('\n'))` - (d) `return csv_string.to_dataframe()`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(df, pd.DataFrame) | passed | 1 |
assert list(df.columns) == ['name', 'age', 'score'] | passed | 1 |
assert df.shape == (3, 3) | passed | 1 |

Question: merge_dataframes
**Return:** A merged DataFrame (inner join on the specified key) **Choose the correct code:** - (a) `return left.join(right, on=on)` - (b) `return pd.concat([left, right])` - (c) `return pd.merge(left, right, on=on, how='inner')` - (d) `return left.combine(right)`

Assertion | Status | Score | Error
--- | --- | --- | ---
assert merged.shape[0] == 2 | passed | 1 |
assert set(merged.columns) == {'id', 'value_left', 'value_right'} | passed | 1 |

Question: select_column
**Return:** A pandas Series for the specified column

Assertion | Status | Score | Error
--- | --- | --- | ---
assert isinstance(age_series, pd.Series) | passed | 1 |
assert age_series.tolist() == [25, 30, 22] | passed | 1 |

✖

### Student Summary

Student | Roll Number | File | Total Marks | Out Of | Percentage
--- | --- | --- | --- | --- | ---
Nitin Sahsani | 2423350 | 2423350_Nitin.Sahsani (2).ipynb | 27 | 58 | 46.55%
Arun Murari Gottipati | 2423360 | ArunMG(2423360).ipynb | 2 | 58 | 3.45%
Harsh Mittal | 2423373 | Harsh CIA.ipynb | 9 | 58 | 15.52%
Mayur garg | 2423358 | MAYUR 2423358 (1).ipynb | 29 | 58 | 50.0%
NISHANT KUMAR | 2423349 | Nishant_Kumar(2423349).ipynb | 12 | 58 | 20.69%
Sarthak Chaudhary | 2423346 | Sarthak_Chaudhary_2423346.ipynb | 29 | 58 | 50.0%
Soham Uday Sahasrabudhe | 2423363 | SohamUdaySahasrabudhe2423363.ipynb | 12 | 58 | 20.69%
Urvi Kamble | 2423383 | Urvi Kamble.ipynb | 9 | 58 | 15.52%
Vaishnavi Santosh Kavishetti | 2423381 | Vaishnavi Kavishetti 2423381 (1).ipynb | 9 | 58 | 15.52%
Vansh Rohida | 2423372 | VanshRohida2423372 (1).ipynb | 16 | 58 | 27.59%
RohanGM | 2423364 | rohan_64.ipynb | 12 | 58 | 20.69%
Kanishka_Singh | 2423376 | student_notebook (1) (1).ipynb | 14 | 58 | 24.14%
Johann Karl | 2423382 | student_notebook (1)(1).ipynb | 33 | 58 | 56.9%
vikram sinha | 2423359 | student_notebook (1)(10).ipynb | 0 | 58 | 0.0%
Kushagra Gulati | 2423347 | student_notebook (1)(2).ipynb | 33 | 58 | 56.9%
Udit Baid | 2423384 | student_notebook (1)(3).ipynb | 26 | 58 | 44.83%
Aakarsh Jawa | 2423380 | student_notebook (1)(4).ipynb | 18 | 58 | 31.03%
ANIRUDDHAN R M | 2423353 | student_notebook (1)(5).ipynb | 13 | 58 | 22.41%
aahaan chatterjee | 2423354 | student_notebook (1)(6).ipynb | 25 | 58 | 43.1%
Siva Samvit Vemuri | 2423348 | student_notebook (1)(7).ipynb | 1 | 58 | 1.72%
Narane Karthic | 2423379 | student_notebook (1)(8).ipynb | 20 | 58 | 34.48%
S.Vaigunda Ram Singh | 2423345 | student_notebook (1)(9).ipynb | 33 | 58 | 56.9%
devansh grover | 2423366 | student_notebook (1).ipynb | 12 | 58 | 20.69%
Farhan Aziz | 2423377 | student_notebook (1)2423377.ipynb | 9 | 58 | 15.52%
Deshpande Rugved Shirish | 2423370 | student_notebook (2).ipynb | 26 | 58 | 44.83%
Tejas Pandey | 2423352 | student_notebook (3)(1).ipynb | 21 | 58 | 36.21%
shaurya | 2423374 | student_notebook (3)(2).ipynb | 13 | 58 | 22.41%
shaurya | 2423374 | student_notebook (3)(3).ipynb | 13 | 58 | 22.41%
shaurya | 2423374 | student_notebook (3)(4).ipynb | 13 | 58 | 22.41%
shaurya | 2423374 | student_notebook (3)(5).ipynb | 13 | 58 | 22.41%
Deshpande Rugved Shirish | 2423370 | student_notebook (3).ipynb | 26 | 58 | 44.83%
shaurya | 2423374 | student_notebook (4)(1).ipynb | 13 | 58 | 22.41%
Divit vats | 2423355 | student_notebook (4)(2).ipynb | 18 | 58 | 31.03%
shaurya | 2423374 | student_notebook (4).ipynb | 13 | 58 | 22.41%
Nimrat Singh | 2423361 | student_notebook Nimrat Singh (3).ipynb | 29 | 58 | 50.0%
Aradhya Mishra | 2423371 | student_notebook(1)(1).ipynb | 12 | 58 | 20.69%
Ashmith B Shetty | 2423378 | student_notebook(1)(2).ipynb | 9 | 58 | 15.52%
devansh | 2423366 | student_notebook(1).ipynb | 13 | 58 | 22.41%
Tejas Pandey | 2423352 | student_notebook(2).ipynb | 21 | 58 | 36.21%
Ashmith B Shetty | 2423378 | student_notebook(3).ipynb | 9 | 58 | 15.52%
Kapil Rawat | 2423356 | student_notebook(4).ipynb | 16 | 58 | 27.59%
Sai_Shobhith | 2423351 | student_notebook(5).ipynb | 21 | 58 | 36.21%
devansh | 2423366 | student_notebook.ipynb | 13 | 58 | 22.41%
Aarav Danani | 2423343 | student_notebook2423343.ipynb | 3 | 58 | 5.17%
Lalit Mohan Kumar | 2423375 | student_notebook_solved.ipynb | 21 | 58 | 36.21%