| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- C
- SSH
- paramiko
- JSON
- Selenium
- pytorch
- Visual Studio
- mysql
- YOLO
- label
- C#
- OpenCV
- 핑거스타일
- windows forms
- pandas
- Docker
- Python
- 컨테이너
- 오류
- error
- 프로그래머스
- C++
- 채보
- Numpy
- ubuntu
- pip
- 기타 연주
- nvidia-smi
- VS Code
- Linux
- Today
- Total
목록Python (107)
기계는 거짓말하지 않는다
파일을 읽어올 때 한글이 깨져 인코딩을 주고 불러오는 경우, # UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb9 in position 0: invalid start byte 와 같은 오류를 볼 때가 있다. 파일의 인코딩이 달라 디코드 할 수 없다는 인코딩 오류이다. 파일을 불러올 때 encoding="euc-kr", encoding="cp949" 와 같은 다른 인코딩 옵션을 주면 된다. 파일 인코딩 형식을 알 수 없다면 찾거나 변경해야 한다.
기본통계 import pandas as pd data = pd.read_csv("임의데이터.csv", encoding="euc-kr", index_col="번호") print(data) print("=" * 30) print(data.describe().round(3)) # 요약 print("-" * 30) print(data[["수량", "단가"]].mean()) # 수량, 단가의 평균 print("-" * 30) print(data[["수량", "단가"]].max()) # 수량, 단가의 최댓값 print("-" * 30) print(data[["수량", "단가"]].min()) # 수량, 단가의 최솟값 print("-" * 30) print(data.loc[[1, 3]].mean()) # 행 선택 후..
Series import pandas as pd fruit = pd.Series([2500, 3800, 1200, 6000], index=['apple', 'banana', 'peer', 'cherry']) print(fruit) print('=' * 20) print(fruit.sort_values(ascending=False)) print('-' * 20) print(fruit.sort_index()) values, index 정렬 가능, axis(축)설정과 ascending(오름차순 or 내림차순)설정도 가능하다. DataFrame 동일하게 axis, ascending 설정 가능 index 정렬 fruitData = {'fruitName':['peer','banana','apple','cherry'..
Series 연산 fruit1 = Series([5, 9, 10, 3], index=['apple', 'banana', 'cherry', 'peer']) fruit2 = Series([3, 2, 9, 5, 10], index=['apple', 'orange', 'banana', 'cherry', 'mango']) print(fruit1) print('-' * 20) print(fruit2) print('=' * 20) print(fruit1 + fruit2) +, -, *, /, %, // (몫 연산) 모두 가능하며 겹치지 않는 인덱스의 value는 계산되지 않고 NaN으로 표기된다. DataFrame 연산 fruitData1 = {'Ohio':[4, 8, 3, 5], 'Texas':[0, 1, 2, 3..
Pandas 파이썬에서 데이터 분석, 조작을 위해 사용되는 라이브러리이다. Pandas에서 제공하는 데이터 자료구조는 Series와 DataFrame 두 가지가 존재한다. Series는 시계열(time series: 일정 시간 간격으로 배치된 데이터들의 수열)과 유사한 데이터로써 index와 value가 있고, DataFrame은 딕셔너리 데이터를 매트릭스 형태로 만들어 준 것 같은 frame을 가지고 있다. 이런 데이터 구조를 통해 시계열, 비시계열 데이터를 통합하여 다룰 수 있다. Install command 창에서 pip install pandas 입력 (pip 패키지 관리자가 있어야 함) Pandas를 사용하기 위해 import pandas를 사용 관행적으로 pd 라는 별칭을 사용하여 import..
Python 코드 작성 시 Direct kernel connection broken 에러를 보는 경우가 있다. 주피터 노트북에서 진행하면 오류 후 정상 작동을 하지 않고 다시 IDE를 재실행 해야 됐다. 주피터 노트북의 exit() 활용에서도 가끔 볼 수 있다. class TempClass: def __init__(self): self.num = 0 self.str = 'String' @property def num(self): return self.num @num.setter def num(self, val): self.num = val @property def str(self): return self.str @str.setter def str(self, str): self.str = str tc = ..
ndarray 배열 슬라이싱 import numpy as np arr = np.arange(0, 10) arr1 = arr[2:6] arr1[0] = 15 # shallow copy print(arr) print(arr1) print() arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) arr1 = arr[:2, 1:3] arr1[0, 0] = 5 # shallow copy print(arr) print(arr1) 배열을 잘라 따로 가지고 올 수 있지만 위와 같은 코드는 얕은 복사가 되며, 원본 데이터도 같이 바뀌게 된다. 아래와 같이 copy()를 이용한다. import numpy as np arr = np.arange(0, 10) arr1 = arr[2:6].c..
NumPy 행렬이나 대규모 다차원 배열을 쉽게 처리할 수 있는 자료구조 기능 지원, 다양한 수치해석, 통계분석 기능을 제공하는 파이썬 라이브러리. NumPy 패키지의 대부분 함수는 C나 Fortran으로 구현되어 우수한 성능 제공 Pandas, Matplotlib 등과 함께 사용 되는것이 일반적임 Install command 창에서 pip install numpy 입력 (pip 패키지 관리자가 있어야 함) python 버전 확인은 커맨드 창에 python --version 또는 py --version 입력. NumPy를 사용하기 위해 import numpy를 사용 관행적으로 np 라는 별칭을 사용하여 import numpy as np로 사용한다. NumPy 배열 클래스 ndarray ndarray 생성 ..