Pandas - NaN is a float

  현상 When I concate or merge, some columns are forced to change to Float64 원인 In  Working with missing data , we saw that pandas primarily uses  NaN  to represent missing data. Because  NaN  is a float, this forces an array of integers with any missing values to become floating point. In some cases, this may not matter much. But if your integer column is, say, an identifier, casting to float can be problematic. Some integers cannot even be represented as floating point numbers. 해결 astype('Int64') 임의변경

Django Admin Log 히스토리

로깅테이블 설계 시 참고   테이블명: django_admin_log object_id: 모델의 primary_key 값 object_repr: __str__() 문자열 action_flag: 1:추가, 2:수정, 3:삭제 change_message: [{"added": {}}] 또는 [{"changed": {"fields": ["필드1", "필드2"]}}]     이런 식으로 저장되며, 화면상 "추가됨" 또는 "뭐뭐 필드가 변경됨" 이라고 나온다.     값은 남지 않는다.     삭제로그인 경우 아무 값도 없다.      엑셀일괄처리한 것은 모두 "update through import_export" 라고 남는다. content_type_id: 모델(django_content_type)의 id

float 대신 decimal 을 쓰자

부동소수점 자료형 float python 에서 소수점이 포함된 숫자는 기본적으로 float 형이다. 컴퓨터 내부 이진수로 저장하기 때문에 십진수와 다르게 대부분 아래와 같이 근사값으로 저장된다.  >>> 1.5 * 0.009 0.013499999999999998 적당히 반올림해서 쓰면 문제가 없지만, 올림 또는 내림 시 문제가 될 수 있다. 이럴땐 Decimal 을 쓰자 >>> from decimal import Decimal >>> Decimal('1.5') * Decimal('0.009') Decimal('0.0135') 참고, nomalize() 로 소수점 뒤 0을 없앨 수 있다. >>> Decimal('12.34500').normalize() Decimal('12.345')

localhost vs 127.0.0.1 vs 0.0.0.0

같지 않다.  localhost localhost는 컴퓨터 네트워크에서 사용하는 루프백 호스트명으로, 자신의 컴퓨터를 의미한다. IPv4에서의 IP 주소는 127.0.0.1이며, IPv6에서는::1로 변환된다. 로컬 컴퓨터를 원격 컴퓨터인것처럼 통신할 수 있어 테스트 목적으로 주로 사용된다. 위키백과 127.0.0.1 The most commonly used IP address on the loopback network 0.0.0.0 인터넷 프로토콜 버전 4에서 주소 0.0.0.0은 유효하지 않거나 알 수 없거나 적용 할 수없는 대상을 지정하는 데 사용되는 라우팅 할 수 없는 메타 주소입니다. 네트워크 도메인 전체를 가리킴

Flask 3분 맛보기

$ pip install flask $ vi myapp.py from flask import Flask app = Flask(__name__) @app.route('/') def index():     return 'Hello Work' if __name__ == '__main__':     app.run(host='0', port=3000) $ python3 myapp.py 

Lightsail browser-based SSH log in fail

이미지
 AWS Lightsail Ubuntu 20.04 apt upgrade 이후 browser-based SSH 연결을 사용할 수 없다. Log in failed. If this instance has just started up, try again in a minute or two. CLIENT_UNAUTHORIZED [769] 이거슨... apt upgrade 할 때, ssh 설정이 바뀌면서 발생한 문제다. (아래와 같은 창이 뜨길래 첫 번째 옵션을 선택했었다) 재설정이 번거롭다면, 두 번째를 선택해서 현재 설정을 유지하도록 하자. 끝.

Django update_or_create 사용 시 주의 - 데이터 중복발생 가능성

  update_or_create() 를 사용해서 편리하게 데이터가 있으면 업데이트, 없으면 생성하고있었는데...  raise self.model.MultipleObjectsReturned( ehr.models.AnnualLeaveDetail.MultipleObjectsReturned: get() returned more than one AnnualLeaveDetail -- it returned 2! 확인해보니, get_or_create()  가 DB레벨의 Unique는 보장하지 않는다. As described above in  get_or_create() , this method is prone to a race-condition which can result in multiple rows being inserted simultaneously if uniqueness is not enforced at the database level. 참조: https://docs.djangoproject.com/en/4.0/ref/models/querysets/#update-or-create But, In my case, 구 버전의 일부 IE에서 중복으로 AJAX 를 던지는 문제로 '추측'하고있다.