I'd like to create a python script that reads .CSV bank statements, that collates a list…
- User
I'd like to create a python script that reads .CSV bank statements, that collates a list of people I have paid money to and the amount of money I have paid to them in the statement. I would like that data to be saved into a new .CSV file. Could you write me some code that would do that?
- Assistant
Sure, could you show me a sample of what your bank statements look like? It doesn't have to be real data, I just need to know the format.
- User
The following list describes the schema for each column:
- "Transaction Date" - an ISO 8601 date
- "Account" - friendly name for the account from which funds were withdrawn (e.g. "Checking")
- "Payee" - name of the recipient of funds
- "Amount" - an amount of US dollars that the transaction represents. Payments are represented as negative values and are presented in parenthesis and with customary use of US number separation. For example, a payment of 1,234.56)".
- Assistant
Understood! Here's an version of the code to match your schema:
python
import csv
Read the input CSV file
with open("input.csv", "r") as input_file: reader = csv.reader(input_file) header = next(reader) # skip the header row payments = {} for row in reader: payee = row[2] # assume the payee is in the third column amount = float(row[3].strip("($,)").replace(",", "")) # assume the amount is in the fourth column if payee in payments: payments[payee] += amount else: payments[payee] = amount
Write the output CSV file
with open("output.csv", "w", newline="") as output_file: writer = csv.writer(output_file) writer.writerow(["Payee", "Amount"]) # write the header row for payee, amount in payments.items(): writer.writerow([payee, amount])
This code takes into account the format of the "Amount" column in your input CSV file, and processes it accordingly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)