title: Extract seasons from datetime pandas
body: <p>I am trying to extract the seasons from a large dataframe with a date time column. This is the code I have used:</p>
  
  <pre><code>def season_of_date(date_UTC):
      year = str(date_UTC.year)
      seasons = {'spring': pd.date_range(start= year +'-03-21 00:00:00', end=year + '-06-20 00:00:00'),
                 'summer': pd.date_range(start= year + '-06-21 00:00:00', end= year + '-09-22 00:00:00'),
                 'autumn': pd.date_range(start= year + '-09-23 00:00:00', end= year + '-12-20 00:00:00')}
      if date_UTC in seasons['spring']:
          return 'spring'
      if date_UTC in seasons['summer']:
          return 'summer'
      if date_UTC in seasons['autumn']:
          return 'autumn'
      else:
          return 'winter'
  
  df['season'] = df.date_UTC.map(season_of_date)
  
  </code></pre>
  
  <p>The issue lies in the fact that I dont know how to handle the hours minutes and seconds in my datetime column, so I end up with a result that is mostly winter, apart from datetime entries when the time is 00:00:00:</p>
  
  <pre><code>date_UTC    season
  616602  2019-11-24 17:00:00 winter
  792460  2019-06-18 13:00:00 winter
  230088  2019-11-30 07:00:00 winter
  560826  2019-05-20 08:00:00 winter
  718547  2019-03-23 04:00:00 winter
  241890  2020-01-11 03:00:00 winter
  513845  2018-12-23 22:00:00 winter
  665954  2019-03-18 00:00:00 winter
  474988  2019-05-20 08:00:00 winter
  120281  2019-04-22 12:00:00 winter
  697519  2018-10-12 05:00:00 winter
  669144  2019-09-10 11:00:00 winter
  310637  2019-11-03 04:00:00 winter
  127973  2018-12-01 10:00:00 winter
  325177  2019-03-16 11:00:00 winter
  785162  2019-05-07 21:00:00 winter
  840131  2018-11-24 00:00:00 autumn
  580472  2020-01-10 19:00:00 winter
  635219  2019-12-16 23:00:00 winter
  799642  2019-11-11 18:00:00 winter
  
  </code></pre>
  
  <p>Can I have some advice on how to modify my code so that the seasons map correctly?</p>
  
  <p>UPDATE:</p>
  
  <p>I modified the code to create a string for the timestamp element and thought this would fix the issue but it didnt.. After making the modification like so I end up with this error:</p>
  
  <pre><code>def season_of_date(date_UTC):
      year = str(date_UTC.year)
      time = str(date_UTC.time)
      seasons = {'spring': pd.date_range(start= year +'-03-21' + time, end=year + '-06-20' + time),
                 'summer': pd.date_range(start= year + '-06-21' + time, end= year + '-09-22' + time),
                 'autumn': pd.date_range(start= year + '-09-23' + time, end= year + '-12-20' + time)}
      if date_UTC in seasons['spring']:
          return 'spring'
      if date_UTC in seasons['summer']:
          return 'summer'
      if date_UTC in seasons['autumn']:
          return 'autumn'
      else:
          return 'winter'
  
  df['season'] = df.date_UTC.map(season_of_date)
  </code></pre>
  
  <pre><code>ValueError: could not convert string to Timestamp
  </code></pre>
  
  <p>SECOND UPDATE:</p>
  
  <p>What I ended up doing was the following, it is fast but I don't like the solution since it wrongly groups whole months into seasons, when actually for a given year a season may start mid way through a month.</p>
  
  <pre><code>df['season'] = (df['date_UTC'].dt.month%12 + 3)//3
  
  seasons = {
               1: 'Winter',
               2: 'Spring',
               3: 'Summer',
               4: 'Autumn'
  }
  
  df['season_name'] = df['season'].map(seasons)
  </code></pre>