python string to datetime 3

[ Python ] 날짜형식의 문자열 타입을 datetime 타입 형식으로 변환

Database, logs 등 날짜형식 데이터를 Python으로 불러와서 처리할 때, 문자열로 저장되게 된다. Python에서 날짜 데이터를 이용하여 그래프를 그리거나 연산을 하기 위해서는 형 변환이 필요하다. datime.datetime.strptime : date 문자열을 datetime 형식으로 변환 from datetime import datetime strtype = '2018-09-15 00:01:14' print(type(strtype)) logdate = datetime.strptime(strtype, '%Y-%m-%d %H:%M:%S') print(type(logdate)) print(logdate) -------------------------------------------------..

[Python] pandas datetime 타입 시간/주/일 더하기

시스템 로그를 분석할 때, 로그시간에 UTC시간을 더해줘야 할 때가 있는데, datetime의 timedelta의 메소드를 이용하여 변환할 수 있겠다. 기준일 from datetime import datetime, timedelta ....... print(data['time']) 0 2019-08-27 00:00:00 1 2019-08-27 00:00:00 2 2019-08-27 00:00:00 3 2019-08-27 00:00:00 4 2019-08-27 00:00:00 ... 373064 2019-08-27 23:59:58 373065 2019-08-27 23:59:59 373066 2019-08-27 23:59:59 373067 2019-08-27 23:59:59 373068 2019-08-27 ..

[Python] datetime.strftime를 이용한 날짜와 시간 변환

from datetime import datetime timenow = datetime.now() # Current Time dt = timenow.strftime('%m-%d-%Y, %H:%M:%S') # datetime print(dt) 04-11-2019, 13:20:17 year1 = timenow.strftime('%Y') # Year with century as a decimal number print(year1) 2019 year2 = timenow.strftime('%y') # Year without century as a zero-padded decimal number print(year2) 19 month1 = timenow.strftime('%m') # Month as a zero-p..