# Django ORM 데이터 tz_info 변경 및 확인
# Django DateTime => datetime.datetime 객체를 출력
import pytz
seoul = pytz.timezone("Asia/Seoul")
# time_check = PriceKRX.objects.all().last().datetime
# time_check.replace(tzinfo=seoul)
# DataFrame 의 tz_info 변경
import pytz
import pandas as pd
seoul = pytz.timezone("Asia/Seoul")
# df.datetime = list(map(
# lambda x : seoul.localize(x),
# df.datetime.tolist())
# )
import pytz
from krxstock.shinhan import get_invest
seoul = pytz.timezone("Asia/Seoul")
df = get_invest("005930")
df["시간"][0].replace(tzinfo=seoul)
# from krx.tasks import get_trading_invest
# get_trading_invest()
from glob import glob
from krx.tasks import get_trader_price
# files = glob("../jupyter/data/trade/csv/*.*")
# get_trader_price(files[0])
import datetime
timestamp = 1528797322
date_time = datetime.datetime.fromtimestamp(timestamp)
print( date_time.strftime("%m/%d/%Y, %H:%M:%S") )
print( date_time.strftime("%d %b, %Y") )
print( date_time.strftime("%d %B, %Y") )
06/12/2018, 18:55:22 12 Jun, 2018 12 June, 2018
# datetime 모듈의 활용
import datetime
print( datetime.datetime.today().strftime('%Y-%m-%d') )
print( datetime.datetime(year=2000, month=1, day=1) )
print( datetime.datetime.strptime('09/19/18 13:55:26', '%m/%d/%y %H:%M:%S') )
datetime.datetime.today() - datetime.timedelta(days=7)
2022-02-11 2000-01-01 00:00:00 2018-09-19 13:55:26
datetime.datetime(2022, 2, 4, 10, 42, 4, 776721)
from datetime import datetime
dateString = "7-May-2018"
dateFormatter = "%u-%b-%Y"
datetime.strptime(dateString, dateFormatter)
datetime.datetime(2018, 5, 1, 0, 0)
time_text = '2019.12.13.AM 00:00'
import pandas as pd
pd.to_datetime(time_text, format='%Y.%m.%d.%p %H:%M').strftime('%Y-%m-%d %H:%M')
'2019-12-13 00:00'
# Check if given numbers are in range using lambda function
test = lambda x : True if (x > 10 and x < 20) else False
print(test(12))
print(test(3))
print(test(24))
# https://thispointer.com/python-how-to-use-if-else-elif-in-lambda-functions/
# https://stackoverflow.com/questions/60261960/how-to-use-lambda-if-else-in-map-on-list-in-python
list(map(lambda x : 'ok' if x == "apple" else None, ['apple', 'banana', 'cherry']))
True False False
['ok', None, None]
test = {
"A":1,
"B":2,
}
test.get("d", 10)
10
test
{'A': 1, 'B': 2}