Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python how to sort by date

from datetime import datetime
my_dates = ['5-Nov-18', '25-Mar-17', '1-Nov-18', '7-Mar-17']
my_dates.sort(key=lambda date: datetime.strptime(date, "%d-%b-%y"))
print(my_dates)
Comment

python order by date

# Sort the dataframe 'df' by the column 'dateColumn' 
df = df.sort_values(by=["dateColumn"])
# -- or --
df.sort_values(by=["dateColumn"], inplace=True, ascending=True)

# Sort by multiple columns
df.sort_values(by=['col1','col2'],ascending=[True,False])
Comment

PREVIOUS NEXT
Code Example
Python :: random in python 
Python :: pyserial read 
Python :: sklearn support vector machine 
Python :: how to execute bash commands in python script 
Python :: install play sound python terminal 
Python :: random.choice 
Python :: python get function name 
Python :: python replace nth occurrence in string 
Python :: python string isdecimal 
Python :: args kwargs python 
Python :: python show charracter code 
Python :: pandas change column dtype 
Python :: urllib request 
Python :: python bar plot groupby 
Python :: dictionary with list as value py 
Python :: python re compile 
Python :: pandas dataframe replace inf 
Python :: matrix inverse python without numpy 
Python :: Python3 boto3 put and put_object to s3 
Python :: Auto-removal of grids by pcolor() and pcolormesh() is deprecated since 3.5 and will be removed two minor releases later; please call grid(False) first. 
Python :: real hour in python 
Python :: how to check if item is in the variable python 
Python :: reset_index(drop=true) 
Python :: matplotlib orange line 
Python :: scipy cosine similarity 
Python :: Convert two lists into a dictionary in python 
Python :: how to create a variable in python 
Python :: read value from entry tkinter 
Python :: remove multiindex pandas 
Python :: python not equal 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =