프로그래밍 언어/Python
[python] 파이썬에서 날짜 포맷 변경하기
파이썬에서 버전 1 다음과 같은 날짜 포맷을 2020. 1. 23. . 2020. 3. 4. 아래와 같이 변환하고자 한다. 2020-01-23 date_row 부분에 변경하고자 하는 내용을 배열로 넣어준다. date_list = pd.DataFrame(date_row, columns=['date']) date_list['date'] = date_list['date'].str.replace('. ', '-') date_list['date'] = date_list['date'].str.replace('.', '-') date_list['date'] = date_list['date'].str.strip('-') date_list['date'] = pd.to_datetime(date_list['date'], f..
[python] 배열 뒤에서부터 출력 [::]
뒤에서 3개만 출력 a = "abc1234가나다" print(a[-3:]) # 가나다 뒤에 3개 빼고 출력 a = "abc1234가나다" print(a[:-3]) # abc1234 뒤에서부터 출력 a = "abc1234가나다" print(a[::-1]) # 다나가4321cba
[python error] 'euc_kr' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
python 에서 csv 를 열 때 encoding 에서 생기는 오류로 utf-8 을 사용해준다. 'cp949' codec can't decode byte 0xbf in position 2: illegal multibyte sequence 'euc_kr' codec can't decode byte 0xbf in position 2: illegal multibyte sequence df.to_csv("/home/test.csv", encoding='utf-8')
[python] dataframe 숫자만 추출, 숫자+문자 추출 (데이터 전처리)
숫자만 추출해서 행 만들기 df['floor'] = df['addr'].str.extract(r'(\d+)') 숫자+'호' 문자열 포함한 행 추출해서 행 만들기 df['floor'] = df['addr'].str.extract(r'(\d+호)')
[python] 'in <string>' requires string as left operand, not float
int 는 len 을 알 수 없는데 길이 구하는 함수 len 을 사용해서 생기는 문제이다. 사용하고자 하는 데이터를 str로 변경해 문자열로 타입을 변경해서 사용한다. len(str(data))
[python] dataframe 컬럼명 변경하기
python 에서 csv 를 사용하는데 컬럼명을 변경해서 사용하고자 한다. 한번에 다 변경 df.columns = ["id","name","addr"] df 특정 컬럼의 컬럼명만 변경 - id 를 ids 로, name 을 rename 으로 변경한다 df.rename(columns={"id":"ids","name":"rename"},inplace = True) df
Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager
python requirement 를 설치하던 중에 생기는 오류로 root 계정말고 다른계정에서 사용한다 Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. pip를 '루트' 사용자로 실행하면 권한이 손상되고 시스템 패키지 관리자와 동작이 충돌할 수 있습니다.
pip install *.whl is not a supported wheel on this platform
whl 파일을 설치하려는데 오류가 나면서 설치가 되지 않았다. 다음 명령어를 사용해서 pip 이 지원되는 버전을 확인하면된다. import wheel.pep425tags print(wheel.pep425tags.get_supported()) 위에서 해당되는 버전을 확인 후 아래에서 파일을 다운받아 사용하면 된다. https://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype
파이썬 설치 경로 찾기
먼저 파이썬 명령어를 칠 수 있도록 한다. python 아래 코드를 작성해서 보면 파이썬 설치경로를 확인할 수 있다. import sys sys.executable
[python] Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-6g2r1v6o/gensim/
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-6g2r1v6o/gensim/ pip install -r requirements.txt 위의 명령어로 설치된 패키지 목록인 requirements.txt 을 생성하는 도중 다음과 같은 에러가 나왔다. setuptools 버전이 낮아서 발생한 오류로 pip3 install --upgrade setuptools 로 해결했다. sudo -H pip install --upgrade --ignore-installed pip setuptools apt-get install -y python3.6-dev libmysqlclient-dev