Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting data into columns
#1
Hi,

I've created regular expressions to extract information regarding 'player', 'ballon d'or', and 'car' from a string. The output is arranged in lines but I want to arrange it in columns, so that player names are shown under the header 'player', number of 'ballon d'or' under 'ballon d'or' and so on. I'm a beginner and not sure in what direction to go from here; I understand that learning pandas is probably the best way to tackle this? Any suggestions welcome. Thanks!

import re

Text = '''
vfbojrgbjgbjnike k k] fd  gbp adidas4fknpumaonobentleyfnvofvVW fobks]bpfporschevfnesfnb opfopve5dfvdsyamaha vdvdfvhondavd
lvpdnronaldovvf dvemessivdef
'''
 
player = re.compile(r'ronaldo|messi')
plrmatches = player.findall(Text)
for match in plrmatches:
    print(match)

bdor = re.compile(r'[\d]|[\d]')
bdormatches = bdor.findall(Text)
for match in bdormatches:
    print(match)

car = re.compile(r'bentley|porsche')
carmatches = car.findall(Text)
for match in carmatches:
    print(match)
Output:
ronaldo messi 4 5 bentley porsche
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting Data into Columns using pdfplumber arvin 17 5,506 Dec-17-2022, 11:59 AM
Last Post: arvin
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,873 Dec-12-2022, 08:22 PM
Last Post: jh67
  Check DataFrames with different sorting in columns and rows Foxyskippy 0 771 Nov-19-2022, 07:49 AM
Last Post: Foxyskippy
  How to keep columns header on excel without change after export data to excel file? ahmedbarbary 0 1,159 May-03-2022, 05:46 PM
Last Post: ahmedbarbary
  Sorting table data Blacktime2 1 1,323 Feb-26-2022, 07:05 PM
Last Post: ibreeden
  Python Pandas: How do I average ONLY the data >1000 from several columns? JaneTan 0 1,468 Jul-17-2021, 01:34 PM
Last Post: JaneTan
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,152 Jul-02-2021, 02:19 PM
Last Post: xtc14
  [Solved] Using readlines to read data file and sum columns Laplace12 4 3,532 Jun-16-2021, 12:46 PM
Last Post: Laplace12
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 6,804 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  Sorting data pprod 4 2,668 Feb-01-2021, 06:51 PM
Last Post: paul18fr

Forum Jump:

User Panel Messages

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