Take this simple dataframe:
df = pd.DataFrame({
'date':['1/15/2017', '2/15/2017','10/15/2016', '3/15/2017'],
'int':[2,3,1,4]
})
I'd like to sort it by the date, and then save it to a CSV without having to:
- Convert dates using
pd.to_datetime(df['date']) - Sort the dataframe using
.sort_values('date') - Convert dates back to
.strftime('%-m/%-d/%Y')
And instead do something like this (which of course, doesn't work):
df.apply(pd.to_dataframe(df['date']).sort_values(by = 'date', inplace = True)
Output:
date kw
2 10/15/2016 1
0 1/15/2017 2
1 2/15/2017 3
3 3/15/2017 4
Is this possible, or should I just stick with the 3-step process?