您好,我想应用如下所示的函数,将日期分解为月份和年份。我还希望将这些结果导出到名为’month’和’year’的另一列中。第二部分是我遇到的问题,即将结果导出到另一列的行中。谢谢。
'Full Date' 'Month' 'Year'07/31/2016 07 201605/28/2011 05 2011
回答:
更详细的方法:
df = pd.DataFrame({'Full Date': ['07/31/2016','05/28/2011']})def date_breaker(date): year = date[-4:] month = date[:2] return (year,month)x = df['Full Date'].map(lambda x: date_breaker(x))df['year'],df['month'] = zip(*x)