커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
날짜 데이터로 변경하기
undefined주차
북마크
구*경
댓글
3
추천
0
조회수
21
조회수
21
답변 완료

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

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


import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

plt.rc('font', family='NanumBarunGothic')


sparta_data = pd.read_table('/content/cohort_data.csv',sep=',')

sparta_data.head()


format='%Y-%m-%dT%H:%M:%S.%f'

sparta_data['start_time'] = pd.to_datetime(sparta_data['created_at'], format=format,infer_datetime_format=True)

sparta_data.tail()



문자로 인식하는 날짜를 데이터로 변경하는 것을 하고 있는데 제가 작성한 것도 아니고 코드스니펫 복사해서 실행하는데 오류라고 뜨네요





작성한 코드 및 에러 메세지

<ipython-input-26-3594944833d6>:11: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.
  sparta_data['start_time'] = pd.to_datetime(sparta_data['created_at'], format=format,infer_datetime_format=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-3594944833d6> in <cell line: 11>()
      9 
     10 format='%Y-%m-%dT%H:%M:%S.%f'
---> 11 sparta_data['start_time'] = pd.to_datetime(sparta_data['created_at'], format=format,infer_datetime_format=True)
     12 sparta_data.tail()


3 frames

/usr/local/lib/python3.10/dist-packages/pandas/core/tools/datetimes.py in _array_strptime_with_fallback(arg, name, utc, fmt, exact, errors)
    517     Call array_strptime, with fallback behavior depending on 'errors'.
    518     """
--> 519     result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors, utc=utc)
    520     if any(tz is not None for tz in timezones):
    521         return _return_parsed_timezone_results(result, timezones, utc, name)

strptime.pyx in pandas._libs.tslibs.strptime.array_strptime()

strptime.pyx in pandas._libs.tslibs.strptime.array_strptime()

ValueError: time data "2022. 8. 15" doesn't match format "%Y-%m-%dT%H:%M:%S.%f", at position 0. 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.


오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.

Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.

Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!




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