sharebook-kr / pykrx

KRX 주식 정보 스크래핑
700 stars 240 forks source link

get_market_trading_value_by_date 에서 오류가 발생합니다. #88

Closed jaehyun0220 closed 1 year ago

jaehyun0220 commented 3 years ago

코드 : from pykrx import stock df = stock.get_market_trading_value_by_date("20210115", "20210122", "005930") print(df.head())

Error 메시지: ValueError: time data -562,644,916,900 doesn't match format specified

TypeError Traceback (most recent call last) C:\Users\clay_desktop\AppData\Roaming\Python\Python37\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object) 1860 try: -> 1861 values, tz_parsed = conversion.datetime_to_datetime64(data) 1862 # If tzaware, these values represent unix timestamps, so we

pandas_libs\tslibs\conversion.pyx in pandas._libs.tslibs.conversion.datetime_to_datetime64()

TypeError: Unrecognized value type: <class 'str'>

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)

in () 1 from pykrx import stock ----> 2 df = stock.get_market_trading_value_by_date("20210115", "20210122", "005930") 3 print(df.head()) F:\Anaconda3\envs\tf2\lib\site-packages\pykrx\stock\api.py in get_market_trading_value_by_date(fromdate, todate, ticker, etf, etn, elw, on, detail, freq) 687 on, detail) 688 else: --> 689 df = krx.get_market_trading_value_and_volume_on_ticker_by_date(fromdate, todate, ticker, "거래대금", on, detail) 690 return resample_ohlcv(df, freq, sum) 691 F:\Anaconda3\envs\tf2\lib\site-packages\pykrx\website\comm\util.py in wrapper(*args, **kwargs) 5 def wrapper(*args, **kwargs): 6 try: ----> 7 return func(*args, **kwargs) 8 except (AttributeError, KeyError, TypeError) as e: 9 logging.info(args, kwargs) F:\Anaconda3\envs\tf2\lib\site-packages\pykrx\website\krx\market\wrap.py in get_market_trading_value_and_volume_on_ticker_by_date(fromdate, todate, ticker, option_a, option_b, detail_view) 533 534 df = df.set_index('날짜') --> 535 df.index = pd.to_datetime(df.index, format='%Y/%m/%d') 536 df = df.replace('[^-\w]', '', regex=True) 537 df = df.replace('', '0') C:\Users\clay_desktop\AppData\Roaming\Python\Python37\site-packages\pandas\core\tools\datetimes.py in to_datetime(arg, errors, dayfirst, yearfirst, utc, box, format, exact, unit, infer_datetime_format, origin, cache) 601 else: 602 convert_listlike = partial(convert_listlike, name=arg.name) --> 603 result = convert_listlike(arg, box, format) 604 elif is_list_like(arg): 605 cache_array = _maybe_cache(arg, format, cache, convert_listlike) C:\Users\clay_desktop\AppData\Roaming\Python\Python37\site-packages\pandas\core\tools\datetimes.py in _convert_listlike_datetimes(arg, box, format, name, tz, unit, errors, infer_datetime_format, dayfirst, yearfirst, exact) 300 arg, dayfirst=dayfirst, yearfirst=yearfirst, 301 utc=utc, errors=errors, require_iso8601=require_iso8601, --> 302 allow_object=True) 303 304 if tz_parsed is not None: C:\Users\clay_desktop\AppData\Roaming\Python\Python37\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object) 1864 return values.view('i8'), tz_parsed 1865 except (ValueError, TypeError): -> 1866 raise e 1867 1868 if tz_parsed is not None: C:\Users\clay_desktop\AppData\Roaming\Python\Python37\site-packages\pandas\core\arrays\datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object) 1855 dayfirst=dayfirst, 1856 yearfirst=yearfirst, -> 1857 require_iso8601=require_iso8601 1858 ) 1859 except ValueError as e: pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime() pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime() ValueError: time data -562,644,916,900 doesn't match format specified
mr-yoo commented 3 years ago

버전을 확인해 주실 수 있나요?

import pykrx
print(pykrx.__version__)

웹 스크래핑이다 보니 웹 서버가 변경되는 일이 빈번합니다. 따라서 많은 경우 버전을 업데이트하면 해결됩니다. pip install -U pykrx

WelsperK commented 2 years ago

업데이트 했더니 제대로 동작합니다!! 감사합니다!!