title: Chronologically sorting date time (YYYY-MM-DD) series with precision down to the level of day
body: <p>I have a pandas datetime series column (in string format) that I would like to have chronologically-sorted. Since the original series are already converted to the YYYY-MM-DD timestamp format like the following:</p>
  
  <pre><code>0     1993-03-25
  1     1985-06-18
  2     1971-07-08
  3     1975-09-27
  4     2000-02-06
  5     1979-07-06
  6     1978-05-18
  7     1989-10-24
  8     1989-10-24
  9     1971-04-10
  10    1985-05-11
  11    2011-04-09
  12    1998-08-01
  13    1972-01-26
  14    1990-05-24
  </code></pre>
  
  <p>Note: it's only a small fraction of the data, it's for illustration purpose</p>
  
  <p>I want to sort them by chronological order down to the precision of 'day' (year --> month --> day) and rank them by their indices in the original series where new index column is on the left and the original (sorted) indices for each datetime string are on the right based on their chronological ranking:</p>
  
  <pre><code>0     10
  1     7
  2     1
  3     3
  4     12
  5     5
  6     4
  7     8
  8     8
  9     0
  10    6
  11    13
  12    11
  13    2
  14    9
  </code></pre>
  
  <p>However, note that there are instances where datetime strings are tied, for example, <code>df[7]</code> and <code>df[8]</code> are the same day, and thus getting the same rank <code>8</code>.</p>
  
  <p>I have used methods like <code>.rank(method='dense').sub(1).astype(int)</code> and <code>.sort_values(kind='mergesort')</code> to sort this datetime series by the sequence of year-month-day, but can't seem to get rid of the 'tied' issue.</p>
  
  <p>Are there better approaches to tackle this tied rank issue and get the output I want?</p>
  
  <p>Thank you.</p>
  
  <p>New Edit</p>
  
  <p>I used the following code to generate the df, the .txt file contains a large number of unorganized text string from which I extracted datetime elements using re.findall(r' ') function.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>import pandas as pd
  import re  
  import datetime
  
  #load text string
  doc = []
  with open('dates.txt') as file:
      for line in file:
          doc.append(line)
  
  df = pd.Series(doc)
  
  # extract datetimes from different datetime patterns, the extracted datetime elements are in string format contained in list [] object
  
  df['date'] = df.str.findall(r'\b....\b')
  
  # manually replace some irregular patterns/expressions
  df['date'].iloc[...] = ['10/21/79']
  df['date'].iloc[...] = ['7/11/2000']
              ...
  df['date'].drop('date', inplace=True)
  
  # convert list object in each cell to string
  df['date'] = df['date'].apply(lambda x: ', '.join(x))
  
  # convert to datetime format and check for NaT cell.
  df['date'] = df['date'].apply(lambda x: pd.to_datetime(x, errors='coerce'))
  
  
     </code></pre>
  </div>
  </div>
  
  The output in each cell of this series is in the form YYYY-MM-DD and dtype =  timestamp.</p>