python 3

ValueError: too many values to unpack (expected 2) request.post(data=params)

python으로 request.post에 data에 JSON 데이터를 넘겼을 때, 아래와 같은 에러가 발생함. ValueError: too many values to unpack (expected 2) JSON List Array인데, 내부에 key-value pair가 여러개 있으면 안된다. 즉, [{"K1":"V", "K2":"V2","K3":"V3"}, {"K1":"V", "K2":"V2","K3":"V3"}] 이 형태는 안됨. https://requests.readthedocs.io/en/latest/api/ data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Reques..

pandas] DataFrame vs. Series

DataFrame을 사용하다 보면 Series type이 리턴될 때가 종종 있다. DataFrame와 Series의 차이는 뭘까? DataFrame이 Series의 상위 호환이라고 생각하면 쉽다. Series는 column의 개수가 1개이다. (쉽게 key-value형태로 사용할 수 있음 serries.to_dict() 하면 됨.) DataFrame은 column의 개수가 N개가 가능하다. Series를 DataFrame으로 바꿀땐, Series.to_frame('column_name')으로 변경하면 된다. series.to_frame('column_name') 참고 사이트: https://stackoverflow.com/questions/26047209/what-is-the-difference-betw..

python 실행 후 shell 종료 시키지 않고 계속 사용하기

import code code.interact(local=locals()) jupyter lab / notebook 같은 걸 보면 kernel을 종료하지 않으면 variable 같은 것들을 계속 확인할 수 있고, 추가로 여러 code를 더 확인해 볼 수 있는데, py 파일로 실행 시키면 해당 동작을 할 수가 없다. 물론 디버깅으로 하면 되지만 간단히 확인하고 싶을 때, shell이 종료되지 않았으면 할 때가 있다. 이럴 때 위의 code를 사용하면 해당 코드가 삽입 된 위치에서 user와 interaction하는 shell mode가 발동 된다. 여러 곳에 쓰면 해당 라인에서 shell이 나온다. (shell에서 나올때는 contrl + d는 동일함)