I have a pandas datetime index that I construct. It may be that through the construction process that the individual members are not in order. I want to sort the index. Is there an obvious way I should be doing this?
What I've done so far is this
import pandas as pd
tseries = pd.to_datetime(['2001-02-04', '2013-08-14', '2008-01-25'])
print 'original unsorted tseries'
for t in tseries:
print t
tseries.values.sort()
print 'new sorted tseries'
for t in tseries:
print t
output:
original unsorted tseries
2001-02-04 00:00:00
2013-08-14 00:00:00
2008-01-25 00:00:00
new sorted tseries
2001-02-04 00:00:00
2008-01-25 00:00:00
2013-08-14 00:00:00
What is the appropriate way to do this? Is what I've done always expected to work?
try
tseries.order()
If you work with a DataFrame, the term is called sort again, i.e. .sort() and .sort_index()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With