title: How can I sort a column of strings in pandas dataframe where I force the order of the letters the column is sorted by?
body: <p>I have a dataframe in python in which one of the columns contains the following letters D W M Y which stand for day, week, month,year. I want to sort my dataframe based on this column in the order I have given it. However the only option I could find was sorting based on alphabetical order which is not what I need. Could you please advise me if this is possible. </p>
  
  <p>The dataframe below is an example of what I am trying to sort. I need it sorted first based on id, then unit where the unit goes D,W,M,Y and then by time. I tried using the regular sort function but it is not working as it is sorting the unit based on alphabetical order. </p>
  
  <p>dataframe</p>
  
  <pre><code>id  time  unit     
  1   3     M
  2   5     Y
  1   12    D
  8   6     W
  6   1     M
  1   2     W
  
  dataframe.sort_values(by=[id,unit,time])
  </code></pre>