我有一个日期时间索引的df.stamp yyyymmdd。我想将它截断为yyyy.mm我的代码如下:
df = pd.concat((pd.read_csv(f, names=['date','bill_id','sponsor_id']) for f in glob.glob('/home/jayaramdas/anaconda3/df/s11?_s_b')))
column_list = ['date', 'bill_id']
df.set_index(pd.to_datetime(df['date']), inplace=True)
df.to_period(freq='M')
df.sort_values(by='date')
date bill_id sponsor_id
date
2007-01-04 2007-01-04 s103-110 1379
2007-01-04 2007-01-04 s68-110 7
2007-01-04 2007-01-04 s25-110 1380
2007-01-04 2007-01-04 s136-110 11