
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
S&P 리스트를 가져와서 소팅할때 head(10), head(50) 은 괜찮은데 head(100)을 쓰면 오류가 납니다.
아마 어떤 종목들 데이터가 없어서 그런게 아닌가 추측이되는데, 이런 경우 final_rate 함수에 쓴 것처럼 try- except 문법으로 해결이 되는것이 아닌지요?
데이터를 불러오는 데까지는 괜찮은데, 소팅을 위한 코드에서 걸립니다
df = df.sort_values(by='rate', ascending = False)
작성한 코드 및 에러 메세지
df = fdr.StockListing('SP500')
df = df[['Symbol', 'Name']].head(100)
df['rate'] = df['Symbol'].apply(final_rate)
df = df.sort_values(by='rate', ascending = False)
df
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-50-0f62acabf876> in <cell line: 6>()
4 df = df[['Symbol', 'Name']].head(100)
5 df['rate'] = df['Symbol'].apply(final_rate)
----> 6 df = df.sort_values(by='rate', ascending = False) # rate 컬럼 데이터에 따라 소팅하되 내림차순(ascending = False))
7
8 df
2 frames
/usr/local/lib/python3.10/dist-packages/pandas/core/sorting.py in nargsort(items, kind, ascending, na_position, key, mask)
436 non_nans = non_nans[::-1]
437 non_nan_idx = non_nan_idx[::-1]
--> 438 indexer = non_nan_idx[non_nans.argsort(kind=kind)]
439 if not ascending:
440 indexer = indexer[::-1]
TypeError: '>' not supported between instances of 'numpy.ndarray' and 'str'
