Pandas Using Sort_values To Sort 2 Dataframes Then Sub-Sort By Date
I have two dataframes consisting a similar type of informatio. I'm attempting to merge them toghether and reorganize them. Here is a sample of the dataframes: df1 = Member Nbr
Solution 1:
by
parameter can be a list of columns so that the dataframe is first sorted by the first column (and for ties by the second column, and for ties by the third column etc.)
df12.sort_values(by=['Member Nbr', 'Date-Join'], inplace=True)
produces
Member Nbr Name-First Name-Last Date-Join
0 20 Zoe Soumas 2011-08-01
1 3128 Julien Bougie 2011-07-22
2 3535 Michel Bibeau 2015-02-18
4 3762 Robert Ortopan 2010-01-31
3 3762 Robert Ortopan 2010-02-28
6 3892 Christian Burnet 2010-03-24
5 3892 Christian Burnet 2010-04-24
7 4116 Christopher Duthie 2014-12-02
8 4700 Manoj Chauhan 2014-11-11
9 4802 Anna Balian 2014-07-26
10 5004 Abdullah Cekic 2012-03-12
12 5022 Robert Ngabirano 2010-06-25
11 5022 Robert Ngabirano 2010-07-28
13 5130 Raymonde Girard 2011-01-04
Note that for this to work correctly, Date-Join column should be of type datetime.
Post a Comment for "Pandas Using Sort_values To Sort 2 Dataframes Then Sub-Sort By Date"