Advertisement
jack06215

[pandas] monthly

Oct 22nd, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. monthly = ['2017-04-01', '2017-05-01', '2017-06-01', '2017-07-01',
  2.            '2017-08-01', '2017-09-01', '2017-10-01', '2017-11-01',
  3.            '2017-12-01', '2018-01-01', '2018-02-01', '2018-03-01',
  4.            '2018-04-01', '2018-05-01', '2018-06-01', '2018-07-01',
  5.            '2018-08-01', '2018-09-01', '2018-10-01']
  6. prev_suffix = []
  7. _flag = False
  8. to_read = []
  9. to_remove = []
  10. kokaku_duration = cols['PARAMS']['KOKAKU_DAYS']
  11. for m in monthly:
  12.     n_acc_list = []
  13.     # determine month suffix
  14.     d_end = pd.to_datetime(m, format='%Y-%m-%d')
  15.     d_begin = d_end - pd.DateOffset(days=int(kokaku_duration - 1))
  16.     date_suffix = list(pd.date_range(start=d_begin, end=d_end, freq='D').strftime('%Y%m').drop_duplicates())
  17.     for _suffix in date_suffix:
  18.         if _flag:
  19.             to_read = list(set(date_suffix) - set(prev_suffix))  
  20.             to_remove = list(set(date_suffix) ^ set(prev_suffix))
  21.             to_remove = list(list(set(to_read) - set(to_remove)) + list(set(to_remove)-set(to_read)))
  22.         else:
  23.             to_read = date_suffix
  24.        
  25.     # update state
  26.     prev_suffix = date_suffix
  27.     _flag = True
  28.     print(_suffix)
  29.     print('to read: {}'.format(to_read))
  30.     print('to delete: {}\n'.format(to_remove))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement