title: Add Multiple Columns to Pandas Dataframe from Function
body: <p>I have a pandas data frame <code>mydf</code> that has two columns,and both columns are datetime datatypes: <code>mydate</code> and <code>mytime</code>. I want to add three more columns: <code>hour</code>, <code>weekday</code>, and <code>weeknum</code>. </p>
  
  <pre><code>def getH(t): #gives the hour
      return t.hour
  def getW(d): #gives the week number
      return d.isocalendar()[1] 
  def getD(d): #gives the weekday
      return d.weekday() # 0 for Monday, 6 for Sunday
  
  mydf["hour"] = mydf.apply(lambda row:getH(row["mytime"]), axis=1)
  mydf["weekday"] = mydf.apply(lambda row:getD(row["mydate"]), axis=1)
  mydf["weeknum"] = mydf.apply(lambda row:getW(row["mydate"]), axis=1)
  </code></pre>
  
  <p>The snippet works, but it's not computationally efficient as it loops through the data frame at least three times. I would just like to know if there's a faster and/or more optimal way to do this. For example, using <code>zip</code> or <code>merge</code>? If, for example, I just create one function that returns three elements, how should I implement this? To illustrate, the function would be:</p>
  
  <pre><code>def getHWd(d,t):
      return t.hour, d.isocalendar()[1], d.weekday()
  </code></pre>