Skip to content

Instantly share code, notes, and snippets.

@defron
Created November 5, 2023 20:38
Show Gist options
  • Select an option

  • Save defron/8726c6a2b5319d6da18b8204fd961818 to your computer and use it in GitHub Desktop.

Select an option

Save defron/8726c6a2b5319d6da18b8204fd961818 to your computer and use it in GitHub Desktop.
python script to split mint transactions by account name
# Python3 program to read mint transaction file and split it into account-based transaction files
import csv
account_txn_dict = dict()
# Open file
# TODO: loop over files in current dir for csvs and do each one
with open('transactions.csv') as txn:
reader = csv.DictReader(txn)
# Iterate over each row in the csv file
# using reader object
for row in reader:
if row["Account Name"] not in account_txn_dict:
account_txn_dict[row["Account Name"]] = []
account_txn_dict[row["Account Name"]].append(row)
for key in account_txn_dict:
filename = key.replace(" ", '-').lower() + '-transactions.csv'
# I'm appending because it'll make it easier when I put this all in a loop later
with open(filename, 'a') as file:
w = csv.DictWriter(file, account_txn_dict[key][0].keys())
w.writeheader()
for transaction in account_txn_dict[key]:
w.writerow(transaction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment