Aug-21-2020, 11:59 PM
(This post was last modified: Aug-21-2020, 11:59 PM by eddywinch82.)
Hi there,
I am using the following line of Code :-
I mean add something to that line of code, so that the Earlier month with a day, is shown 'favoured' before the later month with the same day ? i.e. 10-Jun-2004 is shown before 10-Jul-2004 , 15-May-2004 is shown before 15-Jul-2004 Rows etc. But still dates with day 10 , showing before day 15 Rows.
Update :-
My Code now ends :-
Regards
Eddie Winch
I am using the following line of Code :-
display.sort_values(by=['DATE'])In another code, it correctly outputs the earliest days in the DataFrame Output first i.e. 10 before 15, but not in the month order I want :-
Output:LOCATION DATE DAKOTA HURRICANE SPITFIRE
MyIdx
176 Duxford 10-Jul-2004 D H S
177 Cirencester 10-Jul-2004 D H S
178 Brize Norton 10-Jul-2004 D H S
74 Shrivenham 20:00 10-Jun-2004 D H S
257 Campbletown 15-Aug-2004 D -- S
258 Sunderland 15-Aug-2004 D -- S
261 Scampton 15-Aug-2004 D -- S
200 RIAT Fairford 15-Jul-2004 D -- SS
22 Tilford 15-May-2004 D -- S
23 Abingdon 15-May-2004 D -- S
24 Hyde Heath Village 15-May-2004 D -- S
I want 10th June 2004 first then the 10th of July/s then the 15th of May's then the 15th of August Rows. How do I modify that line of Code, so that I can filter to get that order, without changing the index position of the Rows via code, which I know how to do ?I mean add something to that line of code, so that the Earlier month with a day, is shown 'favoured' before the later month with the same day ? i.e. 10-Jun-2004 is shown before 10-Jul-2004 , 15-May-2004 is shown before 15-Jul-2004 Rows etc. But still dates with day 10 , showing before day 15 Rows.
(df3['DATE'].str.contains('-10$|15$'))Was how I filtered the days.
Update :-
My Code now ends :-
display['DATE'] = pd.to_datetime(display['DATE']) display = display.sort_values(by='DATE', key=lambda col: 100 * col.dt.day + col.dt.month) display['DATE']= pd.to_datetime(display['DATE']).dt.strftime('%d-%b-%Y') displayI was getting an TypeError, as I was using an early version of Pandas, and unfortunately you cant use sort_values with a key Argument, in versions of Pandas below v1.1. So I upgraded to the latest version, and now I get the correct desired DataFrame Output, when using those added lines of Code, when I run my Full Code.
Regards
Eddie Winch