title: Pandas transform date string from format mm/d/yyyy and mm/dd/yyyy to dd.mm.yyyy
body: <p>I have a Pandas data frame which contains a column with dates. The dates are represented in by a string in the format mm/dd/yyyy.</p>
  
  <p>But I have a <strong>problem</strong> with the <strong>format of the day</strong>: Dates until the 9th day of a month are in the format <strong>mm/d/yyyy</strong>. For example the first december 2008 is displayed as 12/1/2008. The 10th day until the end of a month are displayed as <strong>mm/dd/yyyy</strong>. For example the 17th december 2008 is represented by 12/17/2008.</p>
  
  <p>My <strong>target</strong> is to transform the all dates into the form <strong>mm.dd.yyyy</strong>. The could would represent the above expamles as: 12.01.2008 and 12.17.2008</p>
  
  <p>My idea is to just write the day, month and year into seperate columns and then connect the strings in the format mm.dd.yyyy</p>
  
  <p>So far I have tried to withdraw the year and the month just by their position in the string <em>(see code and example below)</em>. But this does not work with the days as there are two cases: the day has either one or two digits.</p>
  
  <p>My idea is to just use a regular expression It is basically the case <em>backslash one or two digits and a backslash</em>. But I do not know how I can express this as a regular expression.</p>
  
  <p>Or is there totally different approach which is much simpler?</p>
  
  <p>Thank you for the help in advance! I am sure that there is a way to do that with regular expressions. But I am also grateful for totally different approaches.</p>
  
  <pre><code>import pandas as pd
  
  # example data frame with dates in the format mm/d/yyyy and mm/dd/yyyy
  df = pd.DataFrame({'date' : ['12/1/2008','12/5/2008','12/10/2008','12/17/2008']})
  
  # withdraw month
  df['month'] = df['date'].str[:2]
  # withdraw year
  df['year'] = df['date'].str[-4:]
  # withdraw day - this is my problem
  df[day] = df['day'] = df['date'].str.extract(r'[\]\d*')
  
  # generate string with dates in the format mm/dd/yyyy
  df['date_new'] = df['month'] + '.' df['day'] + '.' + df['year']
  </code></pre>
  
  <p>From the code of <strong>df['day']</strong> I get the following error: <strong>error: unterminated character set at position 0</strong></p>