Skip to content

Instantly share code, notes, and snippets.

@dadatuputi
Last active August 2, 2023 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadatuputi/b961882b8c8535aa30aacbdc446219c4 to your computer and use it in GitHub Desktop.
Save dadatuputi/b961882b8c8535aa30aacbdc446219c4 to your computer and use it in GitHub Desktop.
Wise CSV to YNAB CSV
import argparse
import pandas as pd
from enum import Enum
class Direction(Enum):
OUT = -1
IN = 1
# Get input and output file as arguments
parser = argparse.ArgumentParser(description="Convert Wise CSV to YNAB CSV")
parser.add_argument('-o', '--output', default="ynab.csv", help="CSV Filename to write to")
parser.add_argument('-d', '--debug', help="Debug by printing out text of supplied PDF", action='store_true')
parser.add_argument('input', help="Wise CSV to import")
args = parser.parse_args()
# Open Wise
wise = pd.read_csv(args.input)
# Filter out CANCELED transactions
wise = wise[wise['Status'] != 'CANCELLED']
# Add multiplier to get value into single column
wise['Mult'] = wise.apply(lambda x: Direction[x['Direction']].value, axis=1)
ynab = pd.DataFrame()
ynab['Date'] = pd.to_datetime(wise['Finished on']).dt.strftime('%Y-%m-%d')
ynab['Payee'] = wise['Target name']
ynab['Memo'] = wise['ID']
ynab['Amount'] = wise['Target amount (after fees)'] * wise['Mult']
print("Writing {} transactions to {}".format(len(ynab), args.output))
ynab.to_csv(args.output, index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment