title: Using Pandas Date Offset with Offset Aliases Directly
body: <p>I'm sure I'm just not searching the correct phrase to answer this, but in Pandas, one can take any DateTime object and add or subtract from it using DateOffset like:</p>
  <p><code>pd.datetime.now() + pd.DateOffset(months=2)</code></p>
  <p><code>pd.datetime.now() + pd.DateOffset(weeks=4)</code></p>
  <p><code>pd.datetime.now() + pd.DateOffset(days=2)</code></p>
  <p>etc.</p>
  <p>But in different context, Offset Aliases are also used:
  <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases" rel="nofollow noreferrer">https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases</a></p>
  <p>My question is is there a way to use DateOffset and pass an Offset Alias to determine the Offset basis?</p>
  <p>Something like: <code>pd.datetime.now() + pd.DateOffset(n=some_int, freq='W')</code> for <code>some_int</code> weeks as an example?</p>
  <p>If that isn't possible, where should I dig in to get something to that effect?</p>
  <p>(The reason is because there is a function I'm utilizing the Offset Alias and I don't want to have to create a long if...else statement to convert the freq string to different instances of <code>pd.DateOffset(weeks=n | years=n | months=n | etc.)</code> I rather the freq string dictate the DateOffset in one line of code and still be dynamic to handle the different frequencies of time.)</p>
  <p>Edited: to add a custom function that takes care of what I need, but it would be nice to have a solution in to_timedelta or DateOffset so that the solution is upstream and more efficient. For example, I'd love to utilize the Business versions of all the <code>freq</code> parameters I'm using so that the <code>n</code> can take in information more natural and raw to the source it came from.</p>
  <pre><code>def datedelta(date, n=0, freq='M'):
      from pandas import to_datetime, DateOffset
      
      if n == 0:
          date_sign = 1
      else:
          date_sign = np.abs(n)/n
          
      freq = freq.lower()
      
      if freq == 'y':
          dtOff = DateOffset(years=abs(n))
      elif freq == 'q':
          dtOff = DateOffset(quarters=abs(n))
      elif freq == 'm':
          dtOff = DateOffset(months=abs(n))
      elif freq == 'w':
          dtOff = DateOffset(weeks=abs(n))
      elif freq == 'd':
          dtOff = DateOffset(days=abs(n))
      else:
          raise ValueError(&quot;The freq parameter not one of the following: {'Y', 'Q', 'M', 'W', 'D'}&quot;)
          
      return to_datetime(date) + date_sign * dtOff
  </code></pre>