Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Aligning data
#2
Numpy is usually for Numbers and not for strings used.
You can do this with Python itself:

from itertools import chain
from operator import itemgetter

# your data
sample_data = [
        ('sample001a.com', -12, 'sample002b.com', -16, 'sample002c.com', -18),
        ('sample002a.com', -14, 'sample003b.com', -16, 'sample004c.com', -22),
        ('sample003a.com', -16, 'sample004b.com', -20, 'sample005c.com', -16),
        ('sample004a.com', -18, 'sample005b.com', -14),
        ('sample005a.com', -12),
    ]

def sort_column(row):
    # ('sample003a.com', -16, 'sample004b.com', -20, 'sample005c.com', -16)
    # this have to be sorted
    # grouping host and value together
    group_by_two = zip(*[iter(row)]*2)
    # you can do this instead with indexing
    sorted_groups = sorted(group_by_two, key=itemgetter(1))
    # group_by_two is the iterator
    # itemgetter get the second element from iterable (1)
    # the list is sorted by this value, the second value
    # now need to flatten the iterable
    # retunring it as imuatble tuple
    return tuple(chain.from_iterable(sorted_groups))


for row in sample_data:
    print(sort_column(row))
How you get the data, is you task. I put an example data set in the top as a nested list.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Aligning data - by gat - Jun-17-2019, 03:37 PM
RE: Aligning data (sorry) :( - by DeaD_EyE - Jun-17-2019, 04:14 PM
RE: Aligning data (sorry) :( - by gat - Jun-18-2019, 09:22 PM
RE: Aligning data (sorry) :( - by Ecniv - Jun-17-2019, 06:25 PM
RE: Aligning data (sorry) :( - by gat - Jun-18-2019, 06:34 PM
RE: Aligning data (sorry) :( - by Ecniv - Jun-18-2019, 07:07 PM
RE: Aligning data - by vindo - Jun-19-2019, 02:12 PM
RE: Aligning data - by gat - Jun-19-2019, 02:49 PM
RE: Aligning data - by Ecniv - Jun-20-2019, 03:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Aligning excel data gat 1 2,258 Jun-17-2019, 07:05 PM
Last Post: michalmonday

Forum Jump:

User Panel Messages

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