Skip to content

Instantly share code, notes, and snippets.

Last active August 26, 2021 08:05
What would you like to do?
Python snippet to convert Revolut export to Wallet
import argparse
import datetime
import pandas as pd
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('input', help='Input revolut export file')
parser.add_argument('--output', default="rev2wall-{CURRENCY}-{TIMESTAMP}.csv", help='Input Revolut file')
return parser.parse_args()
def load_df(input_file):
_df = (pd
.read_csv(input_file, sep=';', parse_dates=['Completed Date '], thousands=',', na_values=[' '])
.rename(columns=lambda x: x.strip())
return _df
def get_currency(df):
return df.filter(like='Paid Out').columns[0][-4:-1]
def wrangle_format(_df, cur):
df = (_df
paid_out_currency=lambda x: x['Paid Out ({})'.format(cur)].astype(float),
paid_in_currency=lambda x: x['Paid In ({})'.format(cur)].astype(float),
amount=lambda x: x.paid_in_currency.where(x.paid_in_currency.notna(), -x.paid_out_currency),
date=lambda x: pd.to_datetime(x['Completed Date']).dt.strftime('%Y/%m/%d'),
note=lambda x: (x['Notes'] + ' ' + x['Category']).str.strip(),
type=lambda x: (x['paid_in_currency'].notna()).map({True: "Income", False: "Expense"}),
.rename(columns=lambda x: x.lower())
.filter(['date', 'currency', 'amount', 'note', 'type'])
return df
def main(input_file):
_df = load_df(input_file)
cur = get_currency(_df)
df = wrangle_format(_df, cur)
return df, cur
if __name__ == "__main__":
args = parse_args()
df, cur = main(args.input)
output = args.output.format(CURRENCY=cur,"%Y%m%dT%H%M%S"))
except KeyError:
output = args.output
df.to_csv(output, index=False, sep=";")
Copy link

troych commented Jul 25, 2019

That worked indeed, finally had some time to update my python install.

Second problem now, for my currency (CHF) revolut uses "," to delimit. So I've got payments of 22,70 for example. This does not seem to work with your snippet, 22,70 gets converted to 2270. If I change the delimiter to "." things work correctly.

Copy link

hnykda commented Jul 25, 2019

Yeah, that's annoying. I guess that could be solved by changing thousands here.

Copy link

troych commented Jul 25, 2019

Yeah, that's annoying. I guess that could be solved by changing thousands here.

Thanks, I've ended up doing it like this:

.read_csv(input_file, sep=';', parse_dates=['Completed Date '], decimal=',', na_values=['  '])

Works as intended now, thank you very much. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment