Write me a simple python script that reads a csv file, asks the user for a question,…
- User
Write me a simple python script that reads a csv file, asks the user for a question, transforms the question into a SQL query, run the query on the data from the csv file, and provides an answer to the user.
Assistant
Here is a simple Python script that does what you described:
pythonimport csv # Read csv file into a list of lists with open('data.csv') as f: reader = csv.reader(f) data = list(reader) # Ask user for a question question = input("Ask a question: ") # Transform question into SQL query sql = f"SELECT * FROM data WHERE {question}" # Run SQL query on data result = [] for row in data: if eval(row[1]): result.append(row) # Print result if result: print("Answer:") for row in result: print(row[0]) else: print("No results found")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.