Sorting data into columns - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Sorting data into columns (/thread-30992.html) |
Sorting data into columns - pprod - Nov-18-2020 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)
|