benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 6cbfe508-0389-5103-ab19-66a777fd879a

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import pandas as pd
import os
import json
from collections import Counter


def task_func(json_dir_path, word_count):
    """ 
    Analyze text content in JSON files from a given directory and find the most common words.
    
    This function reads all the JSON files in the specified directory, extracts the text content from each file,
    and determines the most frequent words. It then returns a list of the specified number of the most common words 
    and their respective counts.
    
    Parameters:
    json_dir_path (str): The directory path where JSON files are stored.
    word_count (int): The number of most common words to return.

    Returns:
    list: A list of tuples with the most common words and their counts.

    Requirements:
    - pandas
    - os
    - json
    - collections.Counter

    Example:
    >>> import tempfile
    >>> fake_data_1 = {"text": "Top visit morning price certainly indicate time. Figure add cold behind customer also."}
    >>> fake_data_2 = {"text": "Itself to current listen. Cover add will feeling head. Perform family affect reduce political general."}
    >>> temp_dir = tempfile.TemporaryDirectory()
    >>> with open(f"{temp_dir.name}/fake_data_1.json", 'w') as f:
    ...     json.dump(fake_data_1, f)
    >>> with open(f"{temp_dir.name}/fake_data_2.json", 'w') as f:
    ...     json.dump(fake_data_2, f)
    >>> task_func(temp_dir.name, 2)
    [('add', 2), ('Top', 1)]
    """

instruct prompt

Analyze text content in JSON files from a given directory and find the most common words. This function reads all the JSON files in the specified directory, extracts the text content from each file, and determines the most frequent words. It then returns a list of the specified number of the most common words and their respective counts.
The function should output with:
    list: A list of tuples with the most common words and their counts.
You should write self-contained code starting with:

Code

import pandas as pd
import os
import json
from collections import Counter
def task_func(json_dir_path, word_count):

code prompt

Code

import pandas as pd
import os
import json
from collections import Counter
def task_func(json_dir_path, word_count):

entry point

task_func

libs

  • pandas
  • collections
  • json
  • os

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