https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.ffill.html#pandas.DataFrame.fillna

https://pandas.pydata.org/docs/reference/api/pandas.read_html.html#pandas-read-html

        data = pd.read_html(str(tbl), displayed_only=False)

Wrap literal string/bytes input in io.StringIO/io.BytesIO instead.

soup = BeautifulSoup(r.text, ‘html.parser’)
startdt = soup.select_one(‘#startDt’)
today_ = startdt[‘value’]
tbl = soup.select(‘table’)

read_html의 str literal is deprecated. use with StringIO wrapping

data = pd.read_html( str(tbl), displayed_only=False)

data = pd.read_html( StringIO(str(tbl)), displayed_only=False)
data[0]

concat with empty is not allowed

pandas v2.1 이후 부터 concat 시 비어 있는 DataFrame/Series 는 deprecated 되었다.

1
2
3
4
5
6
7
# prior usage
dfstocks = pd.DataFrame()

for date in target_range:

df = pd.read_csv(BytesIO(r.content), encoding='euc-kr')
dfstocks = pd.concat([dfstocks, df],axis = 0)

https://stackoverflow.com/questions/77254777/alternative-to-concat-of-empty-dataframe-now-that-it-is-being-deprecated

이런 경우

1
FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.

데이터 프레임에서 바로 concat 을 계속 하려면 colume 을 추가하고 사용하면 된다.

1
2
3
4
5
6
7
column_name = ['종목코드', '종목명', '공매도잔고수량', '상장주식수', '공매도잔고금액', '시가총액', '비중']
dfstocks = pd.DataFrame(columns=column_name)

for date in target_range:

df = pd.read_csv(BytesIO(r.content), encoding='euc-kr')
dfstocks = pd.concat([dfstocks, df],axis = 0)
Author

Gangtai Goh

Posted on

2023-10-31

Updated on

2023-11-01

Licensed under