Add Multiple Columns to Pandas Dataframe from Function

后端 未结 4 1080
执笔经年
执笔经年 2021-01-30 10:41

I have a pandas data frame mydf that has two columns,and both columns are datetime datatypes: mydate and mytime. I want to add three more

4条回答
  •  鱼传尺愫
    2021-01-30 11:31

    def getWd(d):
        d.isocalendar()[1], d.weekday()
    def getH(t):
        return t.hour
    mydf["hour"] = zip(*df["mytime"].map(getH))
    mydf["weekday"], mydf["weeknum"] = zip(*df["mydate"].map(getWd))
    

提交回复
热议问题