Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5장 DBUpdater 문의드립니다. #174

Open
ntosu opened this issue Jun 13, 2023 · 1 comment
Open

5장 DBUpdater 문의드립니다. #174

ntosu opened this issue Jun 13, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@ntosu
Copy link

ntosu commented Jun 13, 2023

Exception occured : 'DataFrame' object has no attribute 'append'
Exception occured : 'DataFrame' object has no attribute 'append'
Exception occured : 'DataFrame' object has no attribute 'append'
Traceback (most recent call last):
File "c:/Users/duddn/OneDrive/바탕 화면/updater.py", line 169, in
dbu.execute_daily()
File "c:/Users/duddn/OneDrive/바탕 화면/updater.py", line 147, in execute_daily
self.update_daily_price(pages_to_fetch)
File "c:/Users/duddn/OneDrive/바탕 화면/updater.py", line 129, in update_daily_price
df = self.read_naver(code, self.codes[code], pages_to_fetch)
File "c:/Users/duddn/OneDrive/바탕 화면/updater.py", line 85, in read_naver
html = BeautifulSoup(requests.get(url,
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 486, in send
resp = conn.urlopen(
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1007, in _send_output
self.send(msg)
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 947, in send
self.connect()
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 184, in connect
conn = self._new_conn()
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 156, in _new_conn
conn = connection.create_connection(
File "C:\Users\duddn\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)

Exception occured : 'DataFrame' object has no attribute 'append'
이게 계속 출력되는 것을 보면 아마
def read_naver(self, code, company, pages_to_fetch)이 함수에서
except Exception as e:
print('Exception occured :', str(e))
return None
이 예외처리가 되는 것 같은데 어떻게 해결해야 할까요?

IDE 환경은 VS code
나머지 라이브러리와 파이썬 버전은 교재에 기재되어있는 것과 같은 버전입니다.
코드는 올려주신 DBUpdaterEX.py 입니다.

@INVESTAR
Copy link
Owner

INVESTAR commented Jun 14, 2023

pandas 최신 버전에서 데이터프레임.append() 메써드가 사라진 것 같습니다.

데이터프레임.append()가 데이터프레임을 세로 축 방향으로만 합칠 수 있다면,
pandas.concat()은 데이터프레임을 세로 뿐만 아니라 가로 축 방향으로도 합칠 수 있기 때문에
데이터프레임.append() 대신 pandas.concat()을 사용하도록 유도하는 것 같습니다.

데이터프레임.append(데이터프레임) 코드를
pd.concat( [데이터프레임, 데이터프레임] ) 코드로 변경해 주시기 바랍니다.

e.g.)

#df = df.append(pd.read_html(requests.get(pg_url, headers={'User-agent': 'Mozilla/5.0'}).text)[0])
df = pd.concat([df, pd.read_html(requests.get(pg_url, headers={'User-agent': 'Mozilla/5.0'}).text)[0]])

보다 상세한 내용은 아래 블로그를 참고하시기 바랍니다.
https://ordo.tistory.com/51

@INVESTAR INVESTAR added the enhancement New feature or request label Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants