benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 20edf78c-d745-5f81-bb41-95ee7338aad8
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import matplotlib.pyplot as plt
import random
import string
import pandas as pd
import seaborn as sns
# Constants
LETTERS = list(string.ascii_lowercase)
def task_func(rows=1000, string_length=3):
"""
Generate a dataframe of random strings and create a heatmap showing the correlation
in the frequency of each letter in these strings.
This function generates a specified number of random strings, each of a given length,
and calculates the frequency of each letter in these strings. A heatmap of the
correlation matrix is then displayed, showing the co-occurrence frequencies of different
letters within these strings.
If the number of rows specified is zero, the function will print a message indicating
that no data is available to generate the heatmap and will return None. Otherwise,
it processes the DataFrame to convert the generated strings into a one-hot encoded format
and then sums up these encodings to calculate the frequency of each letter.
Parameters:
- rows (int, optional): Number of random strings to generate. Must be non-negative.
Default is 1000. If set to 0, the function returns None after printing a message.
- string_length (int, optional): Length of each random string. Must be non-negative.
Default is 3. A value of 0 results in the generation of empty strings.
Returns:
- matplotlib.axes._axes.Axes or None: A seaborn heatmap plot object if
data is generated; otherwise, None.
Requirements:
- random
- string
- pandas
- seaborn
- matplotlib
Note
- If no strings are generated (e.g., rows = 0), the
DataFrame will be empty. In this case, the function prints a message "No data to generate heatmap." and returns None.
- If the DataFrame is not empty, each string is split into its
constituent letters, converted into one-hot encoded format, and then the frequency
of each letter is calculated by summing these encodings.
Example:
>>> ax = task_func(1000, 3)
>>> ax.get_xlim()
(0.0, 26.0)
"""
instruct prompt
Generate a dataframe of random strings and create a heatmap showing the correlation in the frequency of each letter in these strings. This function generates a specified number of random strings, each of a given length, and calculates the frequency of each letter in these strings. A heatmap of the correlation matrix is then displayed, showing the co-occurrence frequencies of different letters within these strings. If the number of rows specified is zero, the function will print a message indicating that no data is available to generate the heatmap and will return None. Otherwise, it processes the DataFrame to convert the generated strings into a one-hot encoded format and then sums up these encodings to calculate the frequency of each letter. Note - If no strings are generated (e.g., rows = 0), the DataFrame will be empty. In this case, the function prints a message "No data to generate heatmap." and returns None. - If the DataFrame is not empty, each string is split into its constituent letters, converted into one-hot encoded format, and then the frequency of each letter is calculated by summing these encodings.
The function should output with:
matplotlib.axes._axes.Axes or None: A seaborn heatmap plot object if
data is generated; otherwise, None.
You should write self-contained code starting with:
Code
import matplotlib.pyplot as plt
import random
import string
import pandas as pd
import seaborn as sns
# Constants
LETTERS = list(string.ascii_lowercase)
def task_func(rows=1000, string_length=3):
code prompt
Code
import matplotlib.pyplot as plt
import random
import string
import pandas as pd
import seaborn as sns
# Constants
LETTERS = list(string.ascii_lowercase)
def task_func(rows=1000, string_length=3):
entry point
task_func
libs
- pandas
- matplotlib
- random
- string
- seaborn
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