본문 바로가기

프로그래밍/Python

(96)
[Python] 이항분포 그래프 그리기 import sys from functools import lru_cache import math import numpy as np import matplotlib.pyplot as plt @lru_cache(None) def ncr(n, r): """조합. 재귀식을 이용함. n이 커지면 스택오버플로우 발생. """ if r in (0, n): return 1 return ncr(n - 1, r) + ncr(n - 1, r - 1) def bidist(n, p): """이항분포""" q = 1 - p dist = np.array([ncr(n, k) * (p ** k) * (q ** (n - k)) for k in range(n + 1)]) return dist def bicoeff(n): """이항계수...
[Python] pandas read_csv issue regarding non-ascii filename (textanal3664) D:\Users\daewon\Downloads\crime>python ana.pyTraceback (most recent call last): File "ana.py", line 5, in df = pd.read_csv('2000년.csv', encoding='euc-kr') File "D:\PythonEnvs\textanal3664\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f return _read(filepath_or_buffer, kwds) File "D:\PythonEnvs\textanal3664\lib\site-packages\pandas\io\parsers.py", line 440, in _read ..
[Python] 실수값 연분수로 근사값 분수 찾기, approx real value using continued fraction import math def contfrac(x, n=10, mx=1000): """ get continued fraction of real x 1 x = r0 + -------------------------- 1 r1 + -------------------- 1 r2 + ------------- r3 + .... n : maximum length of returning r:list mx : maximum ri return : continued fraction, list of integers """ r = [int(x)] if n == 0 or (x - r[0] < 1 / mx): return r return r + contfrac(1 / (x - r[0]), n - 1, mx) def cf2frac(..
[Anaconda] 아나콘다 파이썬의 로컬 업데이트 서버를 어떻게 만들 수 있나? 아나콘다를 인터넷이 안 되는 환경에서 쓸 수 없을까 검색해 보았다. superuser.com (스택익스체인지 포럼중 하나)에서 관련답변을 찾아서, 번역해보았다. 원문은 하이퍼링크를 따라가서 확인 바랍니다. 해보진 않았음. 아나콘다 파이썬의 로컬 업데이트 서버를 어떻게 만들 수 있나? https://superuser.com/a/1003389/114015 HTTP 서버를 만들고 http://repo.continuum.io/pkgs/ 의 모든 내용을 복사해 넣습니다. .condarc 파일을 사용하여이 새 서버를 바라보도록 합니다. 웹 서버를 하나 만들고, 위 주소 퍼블릭 리포지토리에 있는 파일들을 동일한 디렉토리 구조로 배치합니다 (단, /pkgs/free/ 부분은 필요 없습니다). 리포지토리 파일(예 : h..
PIP pylint wrapt install 시 UnicodeDecodeError C:\Users\me>py -3 -m pip install pylintCollecting pylint Downloading http://192.168.123.210:7000/packages/pylint-1.9.1-py2.py3-none-any.whl (687kB) 100% |████████████████████████████████| 696kB ...Collecting astroid=1.6 (from pylint) Downloading http://192.168.123.210:7000/packages/astroid-1.6.4-py2.py3-none-any.whl (290kB) 100% |████████████████████████████████| 296kB 6.6MB/sRequirement already..
[VS2013|PTVS] Python Tool for Visual Studio 가 동작하지 않았다. - VS2015 Pro Update 3 - VS2015 용으로 사용할 수 있는 가장 최신의 PTVS 인 2.2.6 을 다시 설치하였다.설치 후 파이썬 인터프리터 환경 (Python Environments) 이 없어지면서, 파이썬 프로젝트 생성도 되지 않는 문제가 발생하였다.문제발생시에 프로젝트 생성하려고 하면 발생했던 팝업에는 Microsoft.Python.Tools.Interpreter... 어쩌고가 포함되는 메시지가 있었던 것 같다. 잘 기억이 안 난다.인터넷 검색으로 다음과 같은 stack overflow 답변을 찾아 따라한 후 문제가 해결되었다. https://stackoverflow.com/questions/38188868/vs2015-3-ptvs-python-tools-no-longer-wor..
offline virtualenv 시 문제. 인터넷이 끊겨있는 우분투(ubuntu)환경에서 virtualenv 를 실행하여 새로운 환경을 만들려 하였을 때, 에러가 발생했다. python2 -m virtualenv venv venv 라는 이름의 direcotry 에 가상 파이썬2 환경을 만드려 하는 명령이다. File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/index.py", line 423, in find_all_candidates for page in self._get_pages(url_locations, project_name): File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/index.py", line..
[Django] Django import LOCAL settings 문제. Django import LOCAL settings 문제. 원문링크 : https://stackoverflow.com/questions/22904209/django-cannot-import-local-settings 질문 by Brownbay Django 1.7을 Python 3 에서 구동해 보았다. 그런데, manage.py 를 사용할 때, settings.py 의 import local_settings.py 부분이 문제가 생긴다. settings.py 를 직접 실행할 때에는 local_settings.py 는 문제없이 임포트된다. 하지만, manage.py 를 실행하면, 아래와 같이 local_settings.py 모듈을 찾을 수 없다고 나온다.local_settings.py 파일은 settings...