benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a235f682-c19a-5d22-818f-7d5c21217b84

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.feature_extraction.text import CountVectorizer
import matplotlib.pyplot as plt

# Constants
STOP_WORDS = ["a", "an", "the", "in", "on", "at", "and", "or"]


def task_func(file_path, save_path=None):
    """
    This function processes a text dataset from a CSV file, performs text vectorization while excluding specific
    stopwords, and creates a histogram of the ten most common words. The function is robust to different input
    scenarios, such as empty data or data containing only stopwords.

    Parameters:
    - file_path (str): Path to the CSV file containing the text data. The CSV should have a single text column named "Text".
    - save_path (str, optional): Path where the histogram plot will be saved. If not provided, the plot is displayed.

    Returns:
    - matplotlib Axes object: If save_path is not provided and valid words are found in the input, the function
      displays the histogram plot and returns the matplotlib Axes object.
    - None: In two scenarios:
      1. If save_path is provided, saves the plot to the specified location and returns None.
      2. If the input file is empty or contains only stop words, prints a message and returns None.

    Requirements:
    - pandas
    - scikit-learn
    - matplotlib

    Examples:
    >>> ax = task_func('text_data.csv')
    # ax is the matplotlib Axes object for the plot
    >>> result = task_func('text_data.csv', 'output_plot.png')
    # result is None, and the plot is saved to 'output_plot.png'
    """

instruct prompt

This function processes a text dataset from a CSV file, performs text vectorization while excluding specific stopwords, and creates a histogram of the ten most common words. The function is robust to different input scenarios, such as empty data or data containing only stopwords.
The function should output with:
    matplotlib Axes object: If save_path is not provided and valid words are found in the input, the function
    displays the histogram plot and returns the matplotlib Axes object.
    None: In two scenarios:
    1. If save_path is provided, saves the plot to the specified location and returns None.
    2. If the input file is empty or contains only stop words, prints a message and returns None.
You should write self-contained code starting with:

Code

import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
import matplotlib.pyplot as plt
# Constants
STOP_WORDS = ["a", "an", "the", "in", "on", "at", "and", "or"]
def task_func(file_path, save_path=None):

code prompt

Code

import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
import matplotlib.pyplot as plt
# Constants
STOP_WORDS = ["a", "an", "the", "in", "on", "at", "and", "or"]
def task_func(file_path, save_path=None):

entry point

task_func

libs

  • pandas
  • matplotlib
  • sklearn

Discussion

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

Official source

initial import