
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
DataFrame의 일부 열을 가져와 새로운 DataFrame으로 만들 때 대괄호를 두 번 쓰는 이유가 뭔가요?
예를들어,
df = df['Close'].copy() 가 아니라
df = df[['Close']].copy() 로 새로운 DataFrame 형식으로 만드는 이유가 궁금해요
작성한 코드 및 에러 메세지
오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.
df = df['Close'].copy()
df['ma1'] = df['Close'].rolling(3).mean().shift(1)
df['ma2'] = df['Close'].rolling(30).mean().shift(1)
---------------------------------------------------------------------------
ParserError Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/pandas/_libs/tslibs/conversion.pyx in pandas._libs.tslibs.conversion._convert_str_to_tsobject()
11 frames
ParserError: Unknown string format: Close
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
ValueError: could not convert string to Timestamp
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/pandas/core/indexes/datetimes.py in get_loc(self, key, method, tolerance)
681 key = self._maybe_cast_for_get_loc(key)
682 except ValueError as err:
--> 683 raise KeyError(key) from err
684
685 elif isinstance(key, timedelta):
KeyError: 'Close'
