Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. id int_date
  2. 1 20160228
  3. 2 20161231
  4. 3 20160618
  5. 4 20170123
  6. 5 20151124
  7.  
  8. id int_date
  9. 1 02/28/2016
  10. 2 12/31/2016
  11. 3 06/18/2016
  12. 4 01/23/2017
  13. 5 11/24/2015
  14.  
  15. date = datetime(year=int(s[0:4]), month=int(s[4:6]), day=int(s[6:8]))
  16.  
  17. from datetime import datetime
  18. a = '20160228'
  19. date = datetime.strptime(a, '%Y%m%d').strftime('%m/%d/%Y')
  20.  
  21. def get_datetime(date):
  22. date_string = str(date)
  23. return datetime.date(date_string[:3], date_string[4:6], date_string[6:8]
  24.  
  25. import pandas as pd
  26.  
  27. dates = [
  28. 20160228,
  29. 20161231,
  30. 20160618,
  31. 20170123,
  32. 20151124,
  33. ]
  34.  
  35. df = pd.DataFrame(data=list(enumerate(dates, start=1)), columns=['id','int_date'])
  36.  
  37. df[['str_date']] = df[['int_date']].applymap(str).applymap(lambda s: "{}/{}/{}".format(s[4:6],s[6:], s[0:4]))
  38.  
  39. print(df)
  40.  
  41. $ python test.py
  42. id int_date str_date
  43. 0 1 20160228 02/28/2016
  44. 1 2 20161231 12/31/2016
  45. 2 3 20160618 06/18/2016
  46. 3 4 20170123 01/23/2017
  47. 4 5 20151124 11/24/2015
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement