0

I have a dataset like this:

user_id     record_time               accu       lat       lon        bin-lat  bin-lon
0   1335    2017-02-28 18:11:00     21.581  52.130910   -106.639214      207    185     
1   1335    2017-02-28 18:17:00     21.205  52.130910   -106.639214      208    183     
2   1335    2017-02-28 18:22:00     21.998  52.131086   -106.638881      207    185     
3   1335    2017-02-28 18:25:00     28.000  52.130828   -106.637958      209    184     
4   1335    2017-02-28 18:25:00     7.000   52.130806   -106.637825      208    183     
5   1335    2017-02-28 18:25:00     6.000   52.130799   -106.637810      209    184     

I want to sort the whole dataset based on the group of two columns of ('bin-lat' & 'bin-lon'). How can I do that?

cs95
  • 379,657
  • 97
  • 704
  • 746
Mahsa
  • 97
  • 1
  • 7

2 Answers2

2

if you put it into a pandas dataframe you can do a simple sort by columns:

import pandas as pd

your_table = pd.DataFrame(put_your_table_array_here)

sorted_table = your_table.sort_values(by=['bin-lat', 'bin-lon'], ascending=True)
glycoaddict
  • 641
  • 6
  • 19
1
>>> student_objects = [
...     Student('john', 'A', 15),
...     Student('jane', 'B', 12),
...     Student('dave', 'B', 10),
... ]
>>> s = sorted(student_objects, key=attrgetter('age'))     # sort on secondary key
>>> sorted(s, key=attrgetter('grade'), reverse=True)       # now sort on primary key, descending
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

Reference: https://docs.python.org/3/howto/sorting.html#sort-stability-and-complex-sorts

rrkjonnapalli
  • 357
  • 1
  • 3
  • 7