커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
오류 이
undefined주차
북마크
김*린
댓글
27
추천
0
조회수
25
조회수
25
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


data를 불러와서 str형식을 datetime으로 바꾸려 하는데 오류가 발생합니다.


format='%Y-%m-%d %H:%M:%S'

sparta_data['access_date_time'] = pd.to_datetime(sparta_data['access_date'], format=format)




스파르타 즉문즉답




작성한 코드 및 에러 메세지

---------------------------------------------------------------------------

ValueError Traceback (most recent call last)

Cell In[17], line 2

1 format='%Y-%m-%d %H:%M:%S'

----> 2 sparta_data['access_date_time'] = pd.to_datetime(sparta_data['access_date'], format=format)


File c:\Users\zlddp\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\tools\datetimes.py:1050, in to_datetime(arg, errors, dayfirst, yearfirst, utc, format, exact, unit, infer_datetime_format, origin, cache)

1048 result = arg.map(cache_array)

1049 else:

-> 1050 values = convert_listlike(arg._values, format)

1051 result = arg._constructor(values, index=arg.index, name=arg.name)

1052 elif isinstance(arg, (ABCDataFrame, abc.MutableMapping)):


File c:\Users\zlddp\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\tools\datetimes.py:453, in _convert_listlike_datetimes(arg, format, name, utc, unit, errors, dayfirst, yearfirst, exact)

451 # `format` could be inferred, or user didn't ask for mixed-format parsing.

452 if format is not None and format != "mixed":

--> 453 return _array_strptime_with_fallback(arg, name, utc, format, exact, errors)

455 result, tz_parsed = objects_to_datetime64ns(

456 arg,

457 dayfirst=dayfirst,

(...)

461 allow_object=True,

462 )

464 if tz_parsed is not None:

465 # We can take a shortcut since the datetime64 numpy array

...


ValueError: time data "2020.8.3 0:00" doesn't match format "%Y-%m-%d %H:%M:%S", at position 226. You might want to try:

- passing `format` if your strings have a consistent format;

- passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;

- passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this



취소
 공유
취소
댓글 0
댓글 알림
나의얼굴