benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 36a4e871-195d-58f4-bf55-310fee4c5857
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import sqlite3
import pandas as pd
import csv
from io import StringIO
# Constants
DATABASE_NAME = 'test.db'
TABLE_NAME = 'test_table'
def task_func(csv_input):
"""
Imports data from a specified CSV input into an SQLite database and retrieves it as a pandas DataFrame. The function
reads the CSV input (file path or `StringIO`), creates a new database table or replaces an existing one, inserts
data into the table, and finally queries the table to return the data as a DataFrame.
Parameters:
csv_input (str or StringIO): The path to the CSV file or a `StringIO` object containing CSV data.
Returns:
DataFrame: A pandas DataFrame containing the data from the newly populated SQLite database table. The DataFrame
provides a convenient and familiar data structure for further data manipulation and analysis in Python.
Requirements:
- sqlite3
- pandas
- csv
- io
Example:
>>> from io import StringIO
>>> test_csv_data = "id,name\\n1,Alice\\n2,Bob"
>>> test_csv_file = StringIO(test_csv_data) # This is the in-memory CSV data
>>> # Testing the function with the in-memory CSV data
>>> df = task_func(test_csv_file)
>>> print(df)
id name
0 1 Alice
1 2 Bob
"""
instruct prompt
Imports data from a specified CSV input into an SQLite database and retrieves it as a pandas DataFrame. The function reads the CSV input (file path or `StringIO`), creates a new database table or replaces an existing one, inserts data into the table, and finally queries the table to return the data as a DataFrame.
The function should output with:
DataFrame: A pandas DataFrame containing the data from the newly populated SQLite database table. The DataFrame
provides a convenient and familiar data structure for further data manipulation and analysis in Python.
You should write self-contained code starting with:
Code
import sqlite3
import pandas as pd
import csv
from io import StringIO
# Constants
DATABASE_NAME = 'test.db'
TABLE_NAME = 'test_table'
def task_func(csv_input):
code prompt
Code
import sqlite3
import pandas as pd
import csv
from io import StringIO
# Constants
DATABASE_NAME = 'test.db'
TABLE_NAME = 'test_table'
def task_func(csv_input):
entry point
task_func
libs
- sqlite3
- pandas
- io
- csv
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