Python Forum
Grouping Candidates with same name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Grouping Candidates with same name
#4
In order to group first and last name are needed. Therefore this task boils down to how extract names from row.

Rows has different structures or letter types:

ID4,CLARA^OSWALD,F,19890224
ID8,CLARA^oswald,F,19890224
ID14,CLARA^OSWALD^COLEMAN,F,19890224

What these rows have in common? Last name is before and first name after ^. Note, that in one example there is two ^. What will happen if we split on this symbol:

>>> lst = ['ID4,CLARA^OSWALD,F,19890224', 'ID8,CLARA^oswald,F,1989022', 'ID14,CLARA^OSWALD^COLEMAN,F,19890224']
>>> for row in lst:
...     print(row.split('^'))
...
['ID4,CLARA', 'OSWALD,F,19890224']
['ID8,CLARA', 'oswald,F,19890224']
['ID14,CLARA', 'OSWALD', 'COLEMAN,F,19890224']
We can observe, that last name is in first element after comma; first name is in second element, either before first comma or as whole name. Lets modify code so that we will get first and last name:

>>> for row in lst: 
...     splitted = row.split('^') 
...     last_name, first_name = splitted[0].split(',')[1], splitted[1].split(',')[0] 
...     print(last_name, first_name)
...
CLARA OSWALD
CLARA oswald
CLARA OSWALD
We can observe that names have different types of letters, we should unify them either using str.upper() or str.lower() method.

As this is homework you should figure out yourself what to do if you are able to get names out of rows.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Grouping Candidates with same name - by coolperson - Jul-11-2019, 05:11 PM
RE: Grouping Candidates with same name - by scidam - Jul-11-2019, 11:42 PM
RE: Grouping Candidates with same name - by perfringo - Jul-12-2019, 07:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unicode within a RE grouping bluefrog 2 3,123 Jun-09-2018, 09:06 AM
Last Post: snippsat
  column grouping (sum) metalray 2 4,630 Mar-07-2017, 07:15 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020