[Tutor] Finding unique strings.

Roger B. Atkins rba2124 at gmail.com
Fri May 3 15:06:08 EDT 2019


It would probably make things easier if you specified your operating
system, Python version, data file type and location.

Typically, the bank info would be downloadable as a CSV (comma
separated value) file. Assuming that to be the case, and assuming you
are using Windows, and assuming Python 3, and assuming you are downing
loading your data to a file stored on your computer and running your
reader program on the data file, you might start with something like:

#! python 3

import csv

deposits, atm, temp = [], [], []   # initializes column headings to empty lists.

filename = input('Enter file name: ')

with open("C:\\PyScripts\\" + filename, 'r') as f:
        contents = csv.reader(f)
        for row in contents:
                 ...

You would substitute your own column names in place of 'deposits, atm'
and substitute your file path information in place of
"C:\\PyScripts\\".  The first row of the csv file will contain your
column headers. Therefore, as you read through the first row in the
file, row[0] would be the first header, row[1] would be the second
header and so forth.  As you read the second row, row[0] would be the
first value (data element) under the first column header, row[1] would
be the first value under the second column header and so forth.  For
example, if you were searching for deposits, assuming 'Deposits' is
the 3rd column header, you could use code such as deposits += row[2]
to add deposit values to your list of deposits. Such code would be
indented under 'for row in contents' to make it part of the 'for'
loop.

Hopefully this will give you some ideas to get you started.



to


On Fri, May 3, 2019 at 5:40 AM <mhysnm1964 at gmail.com> wrote:
>
> All,
>
>
>
> I have a list of strings which has been downloaded from my bank. I am trying
> to build a program to find the unique string patterns which I want to use
> with a dictionary. So I can group the different transactions together. Below
> are example unique strings which I have manually extracted from the data.
> Everything after the example text is different. I cannot show the full data
> due to privacy.
>
>
>
> WITHDRAWAL AT HANDYBANK
>
> PAYMENT BY AUTHORITY
>
> WITHDRAWAL BY EFTPOS
>
> WITHDRAWAL MOBILE
>
> DEPOSIT          ACCESSPAY
>
>
>
> Note: Some of the entries, have an store name contained in the string
> towards the end. For example:
>
>
>
> WITHDRAWAL BY EFTPOS 0304479 KMART 1075       CASTLE HILL 24/09
>
>
>
> Thus I want to extract the KMART as part of the unique key. As the shown
> example transaction always has a number. I was going to use a test condition
> for the above to test for the number. Then the next word would be added to
> the string for the key.
>
>
>
> I tried to use dictionaries and managed to get unique first words. But got
> stuck at this point and could not work out how to build a unique keyword
> with multiple words. I hope someone can help.
>
>
>
>
>
> Sean
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list