Evaluator Report


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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (most recent call last): File "/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] == 57750failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/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'] == 2failed0Traceback (most recent call last): File "/app/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'] == 0failed0Traceback (most recent call last): File "/app/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'

Anay Mittal — 2423357

File: 2423365 (1).ipynb

Total: 31/58 (53.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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 9210, in groupby return DataFrameGroupBy( ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/groupby/groupby.py", line 1331, in __init__ grouper, exclusions, obj = get_grouper( ^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/groupby/grouper.py", line 1043, in get_grouper raise KeyError(gpr) KeyError: 'Team'
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'select_types'
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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

Aarav Danai — 2423343

File: Aarav Danani 2423343.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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

Arun Murari Gottipati — 2423360

File: ArunMurari(2423360).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 'rest_index'
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 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 'rest_index'
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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_8>", line 2, in get_first_n_rows TypeError: 'method' object is not subscriptable
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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 4112, in __getitem__ return self._getitem_multilevel(key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4170, in _getitem_multilevel loc = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/multi.py", line 3059, in get_loc loc = self._get_level_indexer(key, level=0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/multi.py", line 3410, in _get_level_indexer idx = self._get_loc_single_level_index(level_index, key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/multi.py", line 2999, in _get_loc_single_level_index return level_index.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] == 75failed0Traceback (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 4112, in __getitem__ return self._getitem_multilevel(key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/frame.py", line 4170, in _getitem_multilevel loc = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/multi.py", line 3059, in get_loc loc = self._get_level_indexer(key, level=0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/multi.py", line 3410, in _get_level_indexer idx = self._get_loc_single_level_index(level_index, key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/multi.py", line 2999, in _get_loc_single_level_index return level_index.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

Harsh Mittal — 242333

File: Harsh CIA-1.ipynb

Total: 43/58 (74.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (most recent call last): File "/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] == 57750failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuespassed1
assert (result['Age'] <= 100).all() # No outlierspassed1
assert result.shape[0] == 4 # Charlie (105) removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve']passed1
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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuespassed1
assert (result['Age'] <= 100).all() # No outlierspassed1
assert result.shape[0] == 4 # Charlie (105) removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve']passed1
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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnspassed1
assert result['UpdatedSalary'].iloc[0] == 52500passed1
assert result['UpdatedSalary'].iloc[1] == 57750passed1
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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (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] == 20failed0Traceback (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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20failed0Traceback (most recent call last): File "/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] == 30failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

Lalit Mohan Kumar — 2423375

File: Student Notebook Solved_2.ipynb

Total: 40/58 (68.97%)

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifypassed1
assert list(result['Name']) == ['B', 'C']passed1
assert result['AverageScore'].iloc[0] == 60 # (55+65)/2passed1
assert result['AverageScore'].iloc[1] == 72.5 # (70+75)/2passed1
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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuespassed1
assert (result['Age'] <= 100).all() # No outlierspassed1
assert result.shape[0] == 4 # Charlie (105) removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve']passed1
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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

student name — student roll number

File: Untitled.ipynb

Total: 0/58 (0.0%)

Question: _identity_check_
Student did not customize name/roll_number.
AssertionStatusScoreError
[missing student identity]failed0Student notebook missing personalized name/roll_number. Please define: name = 'Your Name' roll_number = 'Your Roll Number'

Urvi Kamble — 2423383

File: Urvi Kamble (1).ipynb

Total: 38/58 (65.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

krishna jhanwar — 2423344

File: krishna jhanwar(2423344).ipynb

Total: 5/58 (8.62%)

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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 'sample_df' 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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 'column' is not defined

RohanGM — 2423364

File: rohan_64 (2).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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'

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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20failed0Traceback (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] == 30failed0Traceback (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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'

aahaan chatterjee — 2423354

File: student_notebook (1) (2) (1).ipynb

Total: 45/58 (77.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500passed1
assert result['UpdatedSalary'].iloc[1] == 57750passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuespassed1
assert (result['Age'] <= 100).all() # No outlierspassed1
assert result.shape[0] == 4 # Charlie (105) removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve']passed1
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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/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] == 20failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

Farhan Aziz — 2423377

File: student_notebook (1) fr.ipynb

Total: 37/58 (63.79%)

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (most recent call last): File "/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] == 57750failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)(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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnspassed1
assert result['UpdatedSalary'].iloc[0] == 52500passed1
assert result['UpdatedSalary'].iloc[1] == 57750passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/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.indexfailed0Traceback (most recent call last): File "/app/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'] == 4failed0Traceback (most recent call last): File "/app/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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'

S.Vaigunda Ram Singh — 2423345

File: student_notebook (1)(10).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnspassed1
assert result['UpdatedSalary'].iloc[0] == 52500passed1
assert result['UpdatedSalary'].iloc[1] == 57750passed1
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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/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 outliersfailed0Traceback (most recent call last): File "/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) removedfailed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (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] == 20failed0Traceback (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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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))failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20failed0Traceback (most recent call last): File "/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] == 30failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'

vikram sinha — 2423359

File: student_notebook (1)(11).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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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() > 80failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)(12).ipynb

Total: 0/58 (0.0%)

Question: _identity_check_
Student did not customize name/roll_number.
AssertionStatusScoreError
[missing student identity]failed0Student notebook missing personalized name/roll_number. Please define: name = 'Your Name' roll_number = 'Your Roll Number'

devansh grover — 2423366

File: student_notebook (1)(2).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

Johann Karl — 2423382

File: student_notebook (1)(3).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (most recent call last): File "/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] == 57750failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'

Kushagra Gulati — 2423347

File: student_notebook (1)(4).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (most recent call last): File "/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] == 57750failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)(5).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

ANIRUDDHAN R M — 2423353

File: student_notebook (1)(6).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/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.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)(7).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500passed1
assert result['UpdatedSalary'].iloc[1] == 57750passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0passed1
assert result['College'].tolist() == ['IIT', 'Unknown', 'NIT']passed1
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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/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] == 20failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)(8).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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20failed0Traceback (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] == 30failed0Traceback (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()})`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)(9).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnspassed1
assert result['UpdatedSalary'].iloc[0] == 52500passed1
assert result['UpdatedSalary'].iloc[1] == 57750passed1
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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/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 outliersfailed0Traceback (most recent call last): File "/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) removedfailed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/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'] == 2failed0Traceback (most recent call last): File "/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'] == 0failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexfailed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/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] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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))failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/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] == 20failed0Traceback (most recent call last): File "/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] == 30failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'

Anay Mittal — 2423357

File: student_notebook (1).ipynb

Total: 31/58 (53.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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 9210, in groupby return DataFrameGroupBy( ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/groupby/groupby.py", line 1331, in __init__ grouper, exclusions, obj = get_grouper( ^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/groupby/grouper.py", line 1043, in get_grouper raise KeyError(gpr) KeyError: 'Team'
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 6321, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'select_types'
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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert 'AvgSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (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] == 75failed0Traceback (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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

Ashmith B Shetty — 2423378

File: student_notebook (2) (1)(1).ipynb

Total: 7/58 (12.07%)

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 NameError: name 'data' is not defined
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 NameError: name 'data' 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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 first_two['a'].tolist() == [1, 2]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 'data' is not defined

Siva Samvit Vemuri — 2423348

File: student_notebook (2) (1).ipynb

Total: 36/58 (62.07%)

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Charlie']passed1
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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0passed1
assert filled['val'].iloc[2] == 20passed1
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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 'column_name' is not defined

Deshpande Rugved Shirish — 2423370

File: student_notebook (2)(1).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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuespassed1
assert (result['Age'] <= 100).all() # No outlierspassed1
assert result.shape[0] == 4 # Charlie (105) removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve']passed1
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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

student name — student roll number

File: student_notebook (2)(2).ipynb

Total: 0/58 (0.0%)

Question: _identity_check_
Student did not customize name/roll_number.
AssertionStatusScoreError
[missing student identity]failed0Student notebook missing personalized name/roll_number. Please define: name = 'Your Name' roll_number = 'Your Roll Number'

student name — student roll number

File: student_notebook (2).ipynb

Total: 0/58 (0.0%)

Question: _identity_check_
Student did not customize name/roll_number.
AssertionStatusScoreError
[missing student identity]failed0Student notebook missing personalized name/roll_number. Please define: name = 'Your Name' roll_number = 'Your Roll Number'

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (most recent call last): File "/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] == 57750failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuespassed1
assert (result['Age'] <= 100).all() # No outlierspassed1
assert result.shape[0] == 4 # Charlie (105) removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve']passed1
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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

Vaishnavi Santosh Kavishetti — 2423381

File: student_notebook (4) (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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

Krishiv Karthikeyan — 2423362

File: student_notebook Krishiv.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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuespassed1
assert (result['Age'] <= 100).all() # No outlierspassed1
assert result.shape[0] == 4 # Charlie (105) removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve']passed1
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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2passed1
assert list(result['Name']) == ['B', 'D']passed1
assert all((result['Profit'] >= 30) & (result['Profit'] <= 55))passed1
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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
assert stats.loc['count', 'Age'] == 4passed1
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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/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] == 52500failed0Traceback (most recent call last): File "/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] == 57750failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuespassed1
assert (result['Age'] <= 100).all() # No outlierspassed1
assert result.shape[0] == 4 # Charlie (105) removedpassed1
assert list(result['Name']) == ['Alice', 'Bob', 'Diana', 'Eve']passed1
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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1passed1
assert clean_df['x'].iloc[0] == 1passed1
assert clean_df['y'].iloc[0] == 10passed1
Question: fill_missing_college
Write a Python command to fill all missing values in the column 'College' with the text 'Unknown'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20failed0Traceback (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] == 30failed0Traceback (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()})`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)failed0Traceback (most recent call last): File "/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]failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[missing student identity]failed0Student 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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
assert pd.api.types.is_datetime64_any_dtype(converted['date'])failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 == 2023failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert missing['a'] == 1passed1
assert missing['b'] == 2passed1
assert missing['c'] == 0passed1
Question: describe_numeric
**Return:** A pandas DataFrame with descriptive statistics (using .describe())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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]`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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())
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)passed1
assert 'count' in stats.indexpassed1
assert 'mean' in stats.indexpassed1
assert 'std' in stats.indexpassed1
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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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'.
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
assert filtered.shape[0] == 3passed1
assert filtered['score'].min() > 80passed1
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2passed1
assert cols == 3passed1
assert columns == ['x', 'y', 'z']passed1
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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)passed1
assert first_two['a'].tolist() == [1, 2]passed1
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2passed1
assert grouped.loc[grouped['category'] == 'A', 'value'].iloc[0] == 20passed1
assert grouped.loc[grouped['category'] == 'B', 'value'].iloc[0] == 30passed1
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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']passed1
assert df.shape == (3, 3)passed1
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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
assert isinstance(age_series, pd.Series)passed1
assert age_series.tolist() == [25, 30, 22]passed1

vikram sinha — 2423359

File: vikram sinha 2423359.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)`
AssertionStatusScoreError
assert 'UpdatedSalary' in result.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 57750failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result.shape[0] == 2 # Only B and C qualifyfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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)/2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert result['Age'].isnull().sum() == 0 # No missing valuesfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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 outliersfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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) removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert missing['a'] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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.
AssertionStatusScoreError
assert result.shape[0] == 3 # One duplicate removedfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert clean_df.shape[0] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 1failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 10failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'.
AssertionStatusScoreError
assert result['College'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert filled['val'].isnull().sum() == 0failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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}')`
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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 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/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'score'
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 `&`.
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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']failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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))failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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())`
AssertionStatusScoreError
assert rows == 2failed0Traceback (most recent call last): File "/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 == 3failed0Traceback (most recent call last): File "/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']failed0Traceback (most recent call last): File "/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: 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]`
AssertionStatusScoreError
assert first_two.shape == (2, 2)failed0Traceback (most recent call last): File "/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 first_two['a'].tolist() == [1, 2]failed0Traceback (most recent call last): File "/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/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'a'
Question: get_summary_stats
Write a Python command to show summary statistics (mean, median, std, min, max, etc.) for the entire DataFrame.
AssertionStatusScoreError
assert isinstance(stats, pd.DataFrame)failed0Traceback (most recent call last): File "/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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.indexfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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'] == 4failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.
AssertionStatusScoreError
assert grouped.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 20failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 30failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()})`
AssertionStatusScoreError
assert result.shape[0] == 2failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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.columnsfailed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 52500failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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] == 75failed0Traceback (most recent call last): File "/app/src/instantgrade/comparison/comparison_service.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()`
AssertionStatusScoreError
assert isinstance(df, pd.DataFrame)passed1
assert list(df.columns) == ['name', 'age', 'score']failed0Traceback (most recent call last): File "/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 df.shape == (3, 3)failed0Traceback (most recent call last): File "/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: 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)`
AssertionStatusScoreError
assert merged.shape[0] == 2passed1
assert set(merged.columns) == {'id', 'value_left', 'value_right'}passed1
Question: select_column
**Return:** A pandas Series for the specified column
AssertionStatusScoreError
[context setup]failed0Traceback (most recent call last): File "/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/frame.py", line 4113, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pandas/core/indexes/range.py", line 417, in get_loc raise KeyError(key) KeyError: 'column_name'

Student Summary (Highest Marks Across Attempts)

StudentRoll Number Highest MarksOut OfPercentage
ANIRUDDHAN R M2423353135822.41%
Aakarsh Jawa2423380185831.03%
Aarav Danai24233430580.0%
Aarav Danani24233433585.17%
Anay Mittal2423357315853.45%
Aradhya Mishra2423371125820.69%
Arun Murari Gottipati2423360145824.14%
Ashmith B Shetty242337895815.52%
Deshpande Rugved Shirish2423370265844.83%
Divit vats2423355185831.03%
Farhan Aziz2423377375863.79%
Harsh Mittal242333435874.14%
Harsh Mittal242337395815.52%
Johann Karl2423382335856.9%
Kanishka_Singh2423376145824.14%
Kapil Rawat2423356165827.59%
Krishiv Karthikeyan24233620580.0%
Kushagra Gulati2423347335856.9%
Lalit Mohan Kumar2423375405868.97%
Mayur garg2423358295850.0%
NISHANT KUMAR2423349125820.69%
Narane Karthic2423379205834.48%
Nimrat Singh2423361295850.0%
Nitin Sahsani2423350275846.55%
RohanGM2423364125820.69%
S.Vaigunda Ram Singh2423345335856.9%
Sai_Shobhith2423351215836.21%
Sarthak Chaudhary2423346295850.0%
Siva Samvit Vemuri2423348365862.07%
Soham Uday Sahasrabudhe2423363125820.69%
Tejas Pandey2423352215836.21%
Udit Baid2423384295850.0%
Urvi Kamble2423383385865.52%
Vaishnavi Santosh Kavishetti2423381125820.69%
Vansh Rohida2423372165827.59%
aahaan chatterjee2423354455877.59%
devansh2423366135822.41%
devansh grover2423366125820.69%
krishna jhanwar24233445588.62%
shaurya2423374135822.41%
vikram sinha24233593585.17%