커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
2-7 수업에서 S&P500 기업 중 100개 기업에 대해 코드 실행 시 오류
undefined주차
북마크
김*영
댓글
4
추천
0
조회수
8
조회수
8
답변 완료

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

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


강의 후반부에 S&P500 기업 중 100개 기업에 대해 코드를 실행하는 부분이 있는데, 해당 부분에서 에러가 발생하고, 이유를 모르겠습니다..



스파르타 즉문즉답





작성한 코드)

df = fdr.StockListing('SP500')


df = df[['Symbol','Name']].head(100)


df['rate'] = df['Symbol'].apply(final_rate)


cond = df['rate'] > -50
df = df[cond]


df = df.sort_values(by='rate', ascending=False)


df.set_index('Name', inplace=True)


df.plot(kind='bar')


에러 메세지)

HTTP Error 404: Not Found  - symbol "BRKB" not found or invalid periods
HTTP Error 404: Not Found  - symbol "BFB" not found or invalid periods

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-58-e6e12ba0883d> in <cell line: 5>()
      3 df = df[['Symbol','Name']].head(100)
      4 
----> 5 df['rate'] = df['Symbol'].apply(final_rate)
      6 
      7 cond = df['rate'] > -50


6 frames
/usr/local/lib/python3.10/dist-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwargs)
   4769         dtype: float64
   4770         """
-> 4771         return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
   4772 
   4773     def _reduce(

/usr/local/lib/python3.10/dist-packages/pandas/core/apply.py in apply(self)
   1121 
   1122         # self.f is Callable
-> 1123         return self.apply_standard()
   1124 
   1125     def agg(self):

/usr/local/lib/python3.10/dist-packages/pandas/core/apply.py in apply_standard(self)
   1181             # GH#43986 Need to do list(mapped) in order to get treated as nested
   1182             #  See also GH#25959 regarding EA support
-> 1183             return obj._constructor_expanddim(list(mapped), index=obj.index)
   1184         else:
   1185             return obj._constructor(mapped, index=obj.index).__finalize__(

/usr/local/lib/python3.10/dist-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    744                     if columns is not None:
    745                         columns = ensure_index(columns)
--> 746                     arrays, columns, index = nested_data_to_arrays(
    747                         # error: Argument 3 to "nested_data_to_arrays" has incompatible
    748                         # type "Optional[Collection[Any]]"; expected "Optional[Index]"

/usr/local/lib/python3.10/dist-packages/pandas/core/internals/construction.py in nested_data_to_arrays(data, columns, index, dtype)
    508         columns = ensure_index(data[0]._fields)
    509 
--> 510     arrays, columns = to_arrays(data, columns, dtype=dtype)
    511     columns = ensure_index(columns)
    512 

/usr/local/lib/python3.10/dist-packages/pandas/core/internals/construction.py in to_arrays(data, columns, dtype)
    867         arr, columns = _list_of_dict_to_arrays(data, columns)
    868     elif isinstance(data[0], ABCSeries):
--> 869         arr, columns = _list_of_series_to_arrays(data, columns)
    870     else:
    871         # last ditch effort

/usr/local/lib/python3.10/dist-packages/pandas/core/internals/construction.py in _list_of_series_to_arrays(data, columns)
    905         index = getattr(s, "index", None)
    906         if index is None:
--> 907             index = default_index(len(s))
    908 
    909         if id(index) in indexer_cache:

TypeError: object of type 'int' has no len()
취소
 공유
취소
댓글 0
댓글 알림
나의얼굴