benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 375e304a-b3c9-5614-973b-d2b4d3610c9f
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
def task_func(data):
"""
Processes a dataset containing salary information and experience, then plots normalized salary against experience.
The function executes the following steps:
1. Input Validation: Checks if the input data dictionary contains the required keys ('Salary_String' and 'Experience').
Raises a ValueError if the necessary keys are missing.
2. DataFrame Conversion: Converts the input data into a pandas DataFrame for easier manipulation.
3. Empty Data Handling: Checks if the DataFrame is empty. If so, it returns a default Axes instance with
labeled axes but no data plotted. This handles cases where there is no data to plot.
4. Salary Conversion: Converts 'Salary_String' values from comma-separated strings to floats.
It handles potential conversion errors by catching ValueErrors and re-raising them with a custom message.
5. Salary Normalization: Applies Min-Max scaling to normalize the salary values. This step transforms
the salary data into a range between 0 and 1, allowing for easier comparison and visualization.
6. Data Plotting: Creates a scatter plot of the normalized salary against experience using matplotlib.
The plot's axes are labeled accordingly.
Parameters:
- data (dict): A dictionary with two keys: 'Salary_String' and 'Experience'.
'Salary_String' should contain salary values as comma-separated strings.
'Experience' should contain corresponding experience values as integers.
Returns:
- matplotlib.axes.Axes: An Axes instance with the plotted scatter plot.
Raises:
- ValueError: If the input dictionary does not contain the required keys or if data conversion from string to float fails.
Requirements:
- pandas
- sklearn
- matplotlib
Example:
>>> ax = task_func({'Salary_String': ['1,000', '2,000', '3,000'], 'Experience': [1, 2, 3]})
>>> print(ax.get_title())
Normalized Salary vs Experience
"""
instruct prompt
Processes a dataset containing salary information and experience, then plots normalized salary against experience. The function executes the following steps: 1. Input Validation: Checks if the input data dictionary contains the required keys ('Salary_String' and 'Experience'). Raises a ValueError if the necessary keys are missing. 2. DataFrame Conversion: Converts the input data into a pandas DataFrame for easier manipulation. 3. Empty Data Handling: Checks if the DataFrame is empty. If so, it returns a default Axes instance with labeled axes but no data plotted. This handles cases where there is no data to plot. 4. Salary Conversion: Converts 'Salary_String' values from comma-separated strings to floats. It handles potential conversion errors by catching ValueErrors and re-raising them with a custom message. 5. Salary Normalization: Applies Min-Max scaling to normalize the salary values. This step transforms the salary data into a range between 0 and 1, allowing for easier comparison and visualization. 6. Data Plotting: Creates a scatter plot of the normalized salary against experience using matplotlib. The plot's axes are labeled accordingly.
The function should raise the exception for: ValueError: If the input dictionary does not contain the required keys or if data conversion from string to float fails.
The function should output with:
matplotlib.axes.Axes: An Axes instance with the plotted scatter plot.
You should write self-contained code starting with:
Code
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
def task_func(data):
code prompt
Code
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
def task_func(data):
entry point
task_func
libs
- pandas
- matplotlib
- sklearn
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import