Programming/Python 13

[python] zip() 함수

파이썬에서 zip() 함수는동일한 개수로 이루어진 자료형을 묶어주는 역할을 한다. 예를 들어 같은 개수의 원소를 가진 리스트가 있을때, 두개의 리스트를 하나의 자료형으로 구현하고 싶다면, zip()을 사용하면 편리하다. 물론 for loop로 구현할 수도 있지만, 본인이 편한걸 선택해서 사용하면 된다. 예제 간단한 리스트 2개를 하나의 list, dict 로 표현하는 코드다. 간단한 코드 Number = [1,2,3] Name = ['chulsu','younghee','jihea'] # 1. list 만들기 Number_Name_list = list(zip(Number, Name)) print('list zip : ',Number_Name_list) # 2. dict 만들기 Number_Name_dict..

Programming/Python 2021.03.12

[python] pandas Dataframe inplace 옵션 예제

pandas Dataframe의 inplace 옵션에 해서 알아보자. inplace 옵션은 drop과 같은 주요 메소드들이 가지고 있으며, 디폴트 값은 False이다. inplace 옵션이 False이면, 명령어를 실행 한 후 메소드가 적용된 데이터 프레임을 기존 데이터 프레임으로 대체하겠다는 뜻이다. inplace 옵션이 True이면, 명령어를 실행 한 후 메소드가 적용된 데이터 프레임으로 반환 한다. 즉, 삭제 메소드를 실행했다면 반환값은 컬럼이 삭제된 Dataframe이 된다. 말로 설명하니, 구구절절하다. 아래 예제를 보면 한번에 이해가 될 것이다. inplace = True df = pd.DataFrame(data=np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), ..

Programming/Python 2021.01.30

[Error] ImportError: cannot import name 'imread'

현상 scipy.misc에서 imread 패키지 불러올때 아래와 같은 에러가 발생하였다. --------------------------------------------------------------------------- ImportError Traceback (most recent call last) in 9 10 from collections import Counter ---> 11 from scipy.misc import imread 12 from sklearn.feature_extraction.text import TfidfTransformer, CountVectorizer 13 from sklearn.decomposition import NMF, LatentDirichletAllocation..

Programming/Python 2020.12.04

[python] pip install error - Consider using the `--user` option or check the permissions.

pip 모듈 설치시 아래와 같은 permissions 에러 현상이 발생하였다. PS C:\Windows\system32> pip install --upgrade pip Collecting pip Downloading pip-20.2.4-py2.py3-none-any.whl (1.5 MB) |████████████████████████████████| 1.5 MB 46 kB/s Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 20.2.3 Uninstalling pip-20.2.3: Successfully uninstalled pip-20.2.3 ERROR: Could not install..

Programming/Python 2020.10.24

[tensorflow] cannot import name 'Imputer' from 'sklearn.preprocessing'

현상 sklearn.preprocessing에서 Imputer 를 불러올때, 아래와 같은 오류가 발생했다. 에러 화면 해결 방법 Imputer 3 버전 전에 사용되지 않으며 0.22에서 제거되었다. Imputer 모듈을 불러오기 위해선 sklearn.impute를 사용하면 된다. # @deprecated in 0.23 version # from sklearn.preprocessing import Imputer # you should use sklearn.impute from sklearn.impute import SimpleImputer

Programming/Python 2020.10.20

[tensorflow] tensorboard 실행시 cudart64_101.dll not found error

tensorboard 실행시 cudart64_101.dll 가 없다는 에러가 발생하였다. 에러 화면 캡쳐 해결방법은 해당 dll을 아래 사이트에서 설치해주면 된다. 1. 사이트 접속 및 다운로드 CUDA Toolkit 10.1 사이트 CUDA Toolkit 10.1 original Archive Select Target Platform Click on the green buttons that describe your target platform. Only supported platforms will be shown. Operating System Architecture Distribution Version Installer Type Do you want to cross-compile? Yes No Sel..

Programming/Python 2020.10.17

[Python] 'DataFrame' object has no attribute 'ix'

현상 파이썬 실행 중 아래와 같은 에러가 발생하였다. AttributeError: 'DataFrame' object has no attribute 'ix' pandas doc 를 참고하면 ix 함수는 사라지고 .loc 혹은 .iloc로 대체 되었다. 해결방법 해결 방법은 간단한다. ix자리에 .loc 혹은 .iloc로 수정하여 사용하면 된다. 사용 예 ........ # axs[i].plot(data.ix[:, 0]) # axs[i].plot(data.ix[:, 0][(data.ix[:, i+1] == True)], 'ro') axs[i].plot(data.iloc[:,0]) axs[i].plot(data.iloc[:, 0][(data.iloc[:, i + 1] == True)], 'ro') ........

Programming/Python 2020.09.29

[Anaconda] 주요 명령어

버전 확인 conda --version 아나콘다 업데이트 conda update conda 라이브러리 리스트 확인 conda list 라이브러리 설치 # 기본 명령어 conda install {패키지명} # 권장 명령어. 기본 채널에 피키지가 존재하지 않는 경우 PackagesNotFoundError가 발생할 수 있다. conda install -c conda-forge {패키지명} 라이브러리 업데이트 # 특정 라이브러리 업데이트 conda update {패키지명} # 설치되어 있는 모든 라이브러리 업데이트 conda update -all 라이브러리 삭제 conda remove {패키지명} 라이브러리 검색 conda search {패키지명} 아나콘다 환경설정 확인 conda env list conda i..

Programming/Python 2020.04.22

[Python] missingno ModuleNotFoundError

현상 ModuleNotFoundError 발생 import missingno as msno msno.matrix(bike, figsize=(12,5)) --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in ----> 1 import missingno as msno 2 3 msno.matrix(bike, figsize=(12,5)) ModuleNotFoundError: No module named 'missingno' 해결 방법 python 에서 import 하여 사용할때, 기본적인것을 제외한 모듈은 사전에 install을 ..

Programming/Python 2020.04.21

[python] 연산자, 연산자 우선순위, math 내장 함수

복합 연산자 += 처럼 대입 연산자와 다른 연산자를 합쳐 놓은 연산자 assingment 예 설명 += x += y x = x + y 와 동일 -= x -= y x = x - y 와 동일 *= x *= y x = x * y 와 동일 /= x /= y x = x / y 와 동일 //= x //= y x = x // y 와 동일 %= x %= y x = x % y 와 동일 **= x **= y x = x ** y 와 동일 수치 연산 관련 내장 함수 함수 설명 예 abs() 절대값 반환 abs(-10) #10 round() 반올림 계산 round(10) round(10.342, 2) divmod(x,y) x를 y로 나눈 몫과 나머지 반환, (x//y, x%y) 쌍을 반환 divmod(17,4) #(4,1) M..

Programming/Python 2020.04.17