Python Forum
How to parse the data in python
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to parse the data in python
#8
Shouldn't merchant names be like: UA UNION SQUARE 14, 7-ELEVEN 18594, JCPENNEY 1330, Netflix.com, GEICO *AUTO, FARMERS INS BILLIN?

Or should merchants be UA, 7-ELEVEN, JCPENNEY, Netflix.com, GEICO, FARMERS (i.e first word after date)?

One way to achieve these results:

>>> lst = [
       'PURCHASE                                AUTHORIZED ON   09/28 UA UNION SQUARE 14        NEW YORK  NY  S388272071655085   CARD 0057',
       'PURCHASE                                AUTHORIZED ON   09/28 7-ELEVEN 18594            ARVADA  CO  S588272206422481   CARD 7621',
       'PURCHASE                                AUTHORIZED ON   09/30 JCPENNEY 1330             CORPUS CHRIST TX  S468273721740671   CARD 8143'
         ]
>>> splitted = [[''.join(word).strip() for word in row.split('  ') if word] for row in lst]
>>> splitted
['PURCHASE', 'AUTHORIZED ON', '09/28 UA UNION SQUARE 14', 'NEW YORK', 'NY', 'S388272071655085', 'CARD 0057'], ['PURCHASE', 'AUTHORIZED ON', '09/28 7-ELEVEN 18594', 'ARVADA', 'CO', 'S588272206422481', 'CARD 7621'], ['PURCHASE', 'AUTHORIZED ON', '09/30 JCPENNEY 1330', 'CORPUS CHRIST TX', 'S468273721740671', 'CARD 8143']]
>>> merchants = [' '.join(row[2].split()[1:]) for row in splitted]
>>> merchants
['UA UNION SQUARE 14', '7-ELEVEN 18594', 'JCPENNEY 1330']
>>> first_word = [row.split()[0] for row in merchants]
>>> first_word
['UA', '7-ELEVEN', 'JCPENNEY']
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
How to parse the data in python - by sandy - Jan-12-2019, 12:35 AM
RE: How to parse the data in python - by stullis - Jan-12-2019, 02:04 AM
RE: How to parse the data in python - by sandy - Jan-13-2019, 10:40 PM
RE: How to parse the data in python - by sandy - Jan-14-2019, 03:22 AM
RE: How to parse the data in python - by stullis - Jan-14-2019, 03:36 AM
RE: How to parse the data in python - by perfringo - Jan-14-2019, 06:25 AM
RE: How to parse the data in python - by sandy - Jan-14-2019, 06:50 AM
RE: How to parse the data in python - by perfringo - Jan-14-2019, 08:49 AM
RE: How to parse the data in python - by sandy - Jan-14-2019, 06:09 PM
RE: How to parse the data in python - by perfringo - Jan-15-2019, 10:21 AM
RE: How to parse the data in python - by sandy - Jan-15-2019, 05:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 220 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  [split] Parse Nested JSON String in Python mmm07 4 1,579 Mar-28-2023, 06:07 PM
Last Post: snippsat
  python read iperf log and parse throughput jacklee26 4 2,829 Aug-27-2022, 07:04 AM
Last Post: Yoriz
  How to parse a live feed in Python? Daring_T 2 4,180 Jan-20-2022, 04:17 AM
Last Post: Daring_T
  how to parse data fakka 2 1,517 Sep-22-2021, 10:50 PM
Last Post: bowlofred
  Parse BytesIO data GrahamL 2 2,188 Aug-19-2020, 05:09 PM
Last Post: bowlofred
  Parse a REST API call using Python GKT 1 1,920 May-07-2020, 04:15 AM
Last Post: buran
  command line input (arg parse) and data exchange Simba 7 4,356 Dec-06-2019, 11:58 PM
Last Post: Simba
  Read csv file, parse data, and store in a dictionary markellefultz20 4 4,616 Nov-26-2019, 03:33 PM
Last Post: DeaD_EyE
  Parse data from xml file klllmmm 9 9,475 Jun-25-2019, 05:14 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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