@@ -31,6 +31,9 @@ def add_data(self, filename, bank="santander"):
31
31
elif bank == "nationwide" :
32
32
print ("adding nationwide data!" )
33
33
self .new_data = self ._read_nationwide_file (filename )
34
+ elif bank == "lloyds" :
35
+ print ("adding Lloyds Bank data!" )
36
+ self .new_data = self ._read_lloyds_csv (filename )
34
37
35
38
self ._ask_with_guess (self .new_data )
36
39
@@ -218,14 +221,51 @@ def _read_santander_file(self, filename):
218
221
just_numbers = re .sub ("[^0-9\.-]" , "" , data )
219
222
amounts .append (just_numbers .strip ())
220
223
224
+
221
225
df = pd .DataFrame ({'date' :dates , 'desc' :descs , 'amount' :amounts })
222
226
227
+
223
228
df ['amount' ] = df .amount .astype (float )
224
229
df ['desc' ] = df .desc .astype (str )
225
230
df ['date' ] = df .date .astype (str )
226
231
227
232
return df
228
233
234
+ def _read_lloyds_csv (self , filename ):
235
+ """Read a file in the CSV format that Lloyds Bank provides downloads in.
236
+
237
+ Returns a pd.DataFrame with columns of 'date' 0 , 'desc' 4 and 'amount' 5 ."""
238
+
239
+ df = pd .read_csv (filename , skiprows = 0 )
240
+
241
+ """Rename columns """
242
+ #df.columns = ['date', 'desc', 'amount']
243
+ df .rename (
244
+ columns = {
245
+ "Transaction Date" : 'date' ,
246
+ "Transaction Description" : 'desc' ,
247
+ "Debit Amount" : 'amount' ,
248
+ "Credit Amount" : 'creditAmount'
249
+ },
250
+ inplace = True
251
+ )
252
+
253
+ # if its income we still want it in the amount col!
254
+ # manually correct each using 2 cols to create 1 col with either + or - figure
255
+ # lloyds outputs 2 cols, credit and debit, we want 1 col representing a +- figure
256
+ for index , row in df .iterrows ():
257
+ if (row ['amount' ] > 0 ):
258
+ print ('send it negative' )
259
+ df .at [index , 'amount' ] = - row ['amount' ]
260
+ elif (row ['creditAmount' ] > 0 ):
261
+ df .at [index , 'amount' ] = row ['creditAmount' ]
262
+
263
+ # cast types to columns for math
264
+ df = df .astype ({"desc" : str , "date" : str , "amount" : float })
265
+
266
+ return df
267
+
268
+
229
269
def _get_training (self , df ):
230
270
"""Get training data for the classifier, consisting of tuples of
231
271
(text, category)"""
0 commit comments