인프런 커뮤니티 질문&답변

작성자 없음

작성자 정보가 삭제된 글입니다.

파이썬(Python)으로 데이터 기반 주식 퀀트 투자하기 Part1

2.6 reindex() 관련 예제

df1 = fdr.DataReader("005930", '2018-01-02', '2018-10-30') 오류

23.03.04 18:49 작성

·

503

0

오류.jpg안녕하세요

df1 = fdr.DataReader("005930", '2018-01-02', '2018-10-30') 실행했는데 안됩니다

import FinanceDataReader as fdr 은 정상작동하는거 보니 라이브러리는 깔린거 같은데요(스샷)

df1 = fdr.DataReader("005930", '2018-01-02', '2018-10-30') 실행하면 아래와 같이 메시지가 뜹니다

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~\anaconda3\lib\site-packages\pandas\core\computation\scope.py in resolve(self, key, is_local)
    197             if self.has_resolvers:
--> 198                 return self.resolvers[key]
    199 

~\anaconda3\lib\collections\__init__.py in __getitem__(self, key)
    940                 pass
--> 941         return self.__missing__(key)            # support subclasses that define __missing__
    942 

~\anaconda3\lib\collections\__init__.py in __missing__(self, key)
    932     def __missing__(self, key):
--> 933         raise KeyError(key)
    934 

KeyError: 'Timestamp'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~\anaconda3\lib\site-packages\pandas\core\computation\scope.py in resolve(self, key, is_local)
    208                 # e.g., df[df > 0]
--> 209                 return self.temps[key]
    210             except KeyError as err:

KeyError: 'Timestamp'

The above exception was the direct cause of the following exception:

UndefinedVariableError                    Traceback (most recent call last)
~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit_Call(self, node, side, **kwargs)
    665             try:
--> 666                 res = self.visit(node.func)
    667             except UndefinedVariableError:

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit(self, node, **kwargs)
    414         visitor = getattr(self, method)
--> 415         return visitor(node, **kwargs)
    416 

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit_Name(self, node, **kwargs)
    548     def visit_Name(self, node, **kwargs):
--> 549         return self.term_type(node.id, self.env, **kwargs)
    550 

~\anaconda3\lib\site-packages\pandas\core\computation\ops.py in __init__(self, name, env, side, encoding)
     84         self.is_local = tname.startswith(LOCAL_TAG) or tname in DEFAULT_GLOBALS
---> 85         self._value = self._resolve_name()
     86         self.encoding = encoding

~\anaconda3\lib\site-packages\pandas\core\computation\ops.py in _resolve_name(self)
    108 
--> 109         res = self.env.resolve(local_name, is_local=is_local)
    110         self.update(res)

~\anaconda3\lib\site-packages\pandas\core\computation\scope.py in resolve(self, key, is_local)
    210             except KeyError as err:
--> 211                 raise UndefinedVariableError(key, is_local) from err
    212 

UndefinedVariableError: name 'Timestamp' is not defined

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_6828\4160705912.py in <module>
----> 1 df1 = fdr.DataReader("005930", '2018-01-02', '2018-10-30')

~\anaconda3\lib\site-packages\FinanceDataReader\data.py in DataReader(symbol, start, end, exchange, kind)
     17     if (symbol.isdigit() and len(symbol)==6 and exchange==None) or \
     18        (symbol.isdigit() and exchange and exchange.upper() in ['KRX', '한국거래소']):
---> 19         return NaverDailyReader(symbol, start, end, exchange, kind).read()
     20 
     21     if (symbol.isdigit() and exchange and exchange.upper() in ['KRX-DELISTING']):

~\anaconda3\lib\site-packages\FinanceDataReader\naver\data.py in read(self)
     27         df['Change'] = df['Close'].pct_change()
     28 
---> 29         return df.query('index>=%r and index<=%r' % (self.start, self.end))

~\anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    329                     stacklevel=find_stack_level(),
    330                 )
--> 331             return func(*args, **kwargs)
    332 
    333         # error: "Callable[[VarArg(Any), KwArg(Any)], Any]" has no

~\anaconda3\lib\site-packages\pandas\core\frame.py in query(self, expr, inplace, **kwargs)
   4472         kwargs["level"] = kwargs.pop("level", 0) + 2
   4473         kwargs["target"] = None
-> 4474         res = self.eval(expr, **kwargs)
   4475 
   4476         try:

~\anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    329                     stacklevel=find_stack_level(),
    330                 )
--> 331             return func(*args, **kwargs)
    332 
    333         # error: "Callable[[VarArg(Any), KwArg(Any)], Any]" has no

~\anaconda3\lib\site-packages\pandas\core\frame.py in eval(self, expr, inplace, **kwargs)
   4610         kwargs["resolvers"] = tuple(kwargs.get("resolvers", ())) + resolvers
   4611 
-> 4612         return _eval(expr, inplace=inplace, **kwargs)
   4613 
   4614     def select_dtypes(self, include=None, exclude=None) -> DataFrame:

~\anaconda3\lib\site-packages\pandas\core\computation\eval.py in eval(expr, parser, engine, truediv, local_dict, global_dict, resolvers, level, target, inplace)
    351         )
    352 
--> 353         parsed_expr = Expr(expr, engine=engine, parser=parser, env=env)
    354 
    355         # construct the engine and evaluate the parsed expression

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in __init__(self, expr, engine, parser, env, level)
    811         self.parser = parser
    812         self._visitor = PARSERS[parser](self.env, self.engine, self.parser)
--> 813         self.terms = self.parse()
    814 
    815     @property

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in parse(self)
    830         Parse an expression.
    831         """
--> 832         return self._visitor.visit(self.expr)
    833 
    834     @property

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit(self, node, **kwargs)
    413         method = "visit_" + type(node).__name__
    414         visitor = getattr(self, method)
--> 415         return visitor(node, **kwargs)
    416 
    417     def visit_Module(self, node, **kwargs):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit_Module(self, node, **kwargs)
    419             raise SyntaxError("only a single expression is allowed")
    420         expr = node.body[0]
--> 421         return self.visit(expr, **kwargs)
    422 
    423     def visit_Expr(self, node, **kwargs):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit(self, node, **kwargs)
    413         method = "visit_" + type(node).__name__
    414         visitor = getattr(self, method)
--> 415         return visitor(node, **kwargs)
    416 
    417     def visit_Module(self, node, **kwargs):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit_Expr(self, node, **kwargs)
    422 
    423     def visit_Expr(self, node, **kwargs):
--> 424         return self.visit(node.value, **kwargs)
    425 
    426     def _rewrite_membership_op(self, node, left, right):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit(self, node, **kwargs)
    413         method = "visit_" + type(node).__name__
    414         visitor = getattr(self, method)
--> 415         return visitor(node, **kwargs)
    416 
    417     def visit_Module(self, node, **kwargs):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit_BoolOp(self, node, **kwargs)
    748 
    749         operands = node.values
--> 750         return reduce(visitor, operands)
    751 
    752 

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visitor(x, y)
    741     def visit_BoolOp(self, node, **kwargs):
    742         def visitor(x, y):
--> 743             lhs = self._try_visit_binop(x)
    744             rhs = self._try_visit_binop(y)
    745 

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in _try_visit_binop(self, bop)
    737         if isinstance(bop, (Op, Term)):
    738             return bop
--> 739         return self.visit(bop)
    740 
    741     def visit_BoolOp(self, node, **kwargs):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit(self, node, **kwargs)
    413         method = "visit_" + type(node).__name__
    414         visitor = getattr(self, method)
--> 415         return visitor(node, **kwargs)
    416 
    417     def visit_Module(self, node, **kwargs):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit_Compare(self, node, **kwargs)
    721             op = self.translate_In(ops[0])
    722             binop = ast.BinOp(op=op, left=node.left, right=comps[0])
--> 723             return self.visit(binop)
    724 
    725         # recursive case: we have a chained comparison, a CMP b CMP c, etc.

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit(self, node, **kwargs)
    413         method = "visit_" + type(node).__name__
    414         visitor = getattr(self, method)
--> 415         return visitor(node, **kwargs)
    416 
    417     def visit_Module(self, node, **kwargs):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit_BinOp(self, node, **kwargs)
    534 
    535     def visit_BinOp(self, node, **kwargs):
--> 536         op, op_class, left, right = self._maybe_transform_eq_ne(node)
    537         left, right = self._maybe_downcast_constants(left, right)
    538         return self._maybe_evaluate_binop(op, op_class, left, right)

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in _maybe_transform_eq_ne(self, node, left, right)
    456             left = self.visit(node.left, side="left")
    457         if right is None:
--> 458             right = self.visit(node.right, side="right")
    459         op, op_class, left, right = self._rewrite_membership_op(node, left, right)
    460         return op, op_class, left, right

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit(self, node, **kwargs)
    413         method = "visit_" + type(node).__name__
    414         visitor = getattr(self, method)
--> 415         return visitor(node, **kwargs)
    416 
    417     def visit_Module(self, node, **kwargs):

~\anaconda3\lib\site-packages\pandas\core\computation\expr.py in visit_Call(self, node, side, **kwargs)
    668                 # Check if this is a supported function name
    669                 try:
--> 670                     res = FuncNode(node.func.id)
    671                 except ValueError:
    672                     # Raise original error

~\anaconda3\lib\site-packages\pandas\core\computation\ops.py in __init__(self, name)
    612     def __init__(self, name: str) -> None:
    613         if name not in MATHOPS:
--> 614             raise ValueError(f'"{name}" is not a supported function')
    615         self.name = name
    616         self.func = getattr(np, name)

ValueError: "Timestamp" is not a supported function

 

 

 

답변 2

0

nathan님의 프로필 이미지

2023. 03. 29. 01:51

해결책 공유 가능하신가요?

0

ktu5646님의 프로필 이미지

2023. 03. 05. 07:22

해결됐습니다

dkdlel444님의 프로필 이미지

2023. 08. 29. 20:54

어떻게 해결하셨을까요?

작성자 없음

작성자 정보가 삭제된 글입니다.

질문하기