일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- count()
- matplotlib
- dendrogram
- 분류 결과표
- function
- elbow method
- 덴드로그램
- append()
- del
- DataAccess
- DataFrame
- numpy
- IN
- Dictionary
- pandas
- string
- Python
- 최솟값
- list
- insert()
- 반복문
- nan
- sklearn
- analizer
- 최댓값
- data
- Machine Learning
- len()
- wcss
- hierarchical_clustering
- Today
- Total
목록Python (54)
개발공부

import pandas as pd df = pd.DataFrame({'Employee ID':[111, 222, 333, 444], 'Employee Name':['Chanel', 'Steve', 'Mitch', 'Bird'], 'Salary [$/h]':[35, 29, 38, 20], 'Years of Experience':[3, 4 ,9, 1]}) df sort_index() 인덱스에 기반하여 정렬한다. # ascending = True면 오름차순, False면 내림차순 df.sort_index() sort_values() 데이터에 기반하여 정렬한다. # 경력을 오름차순으로 정렬 df.sort_values('Years of Experience') # 경력을 내림차순으로 정렬 df.sort_value..

groupby() 카테고리컬 데이터의 각 데이터별로 묶어서 처리하는 방법 카테고리컬 데이터인지 알 수 있는 방법은 nunique()와 unique()를 이용하면 된다. # 카테고리컬 데이터 (Categorical Data) # 갯수가 정해져있고 그 안에서 나눌 수 있는 것 >>> df['Year'].nunique() 3 >>> df['Year'].unique() array([1990, 1991, 1992], dtype=int64) df의 행갯수는 8개인데 Year 컬럼의 유니크한 갯수는 3개이다. 그러므로 Year의 데이터는 카테고리컬 데이터이다. # 각 년도'별로' 연봉 총합 구하라 >>> df.groupby('Year')['Salary'].sum() Year 1990 153000 1991 162000..

items2 = [{'bikes': 20, 'pants': 30, 'watches': 35, 'shirts': 15, 'shoes':8, 'suits':45}, {'watches': 10, 'glasses': 50, 'bikes': 15, 'pants':5, 'shirts': 2, 'shoes':5, 'suits':7}, {'bikes': 20, 'pants': 30, 'watches': 35, 'glasses': 4, 'shoes':10}] df = pd.DataFrame(data = items2, index = ['store 1', 'store 2', 'store 3']) df NaN 이 얼마나 있는지 파악 isna() df.isna() # 각 컬럼별로 NaN의 수 df.isna().sum() # 총..

df 인덱스명 변경 # store 3 를 last store 로변경하기 df.rename( index = {'store 3' : 'last store'} ) 컬럼명 변경 # bikes 컬럼을 hat 으로 바꾸고, suits 컬럼은 shoes 로 바꾸기 df.rename ( columns= {'bikes' : 'hat', 'suits' : 'shoes'}) 컬럼을 인덱스로 사용 set_index() df # name 컬럼을 인덱스로 사용하고 싶을 때 # set_index()를 사용한다 # inplace = True => 원본 데이터 변경 여부 df.set_index('name', inplace = True) df 사용했던 컬럼을 원래대로 되돌리기 reset_index() df.reset_index(inpl..

Pandas Dataframe 새로운 컬럼 생성 df df['shirts'] = [15, 2] df # pants 컬럼의 데이터와 shirts 컬럼의 데이터를 합해서, suits 컬럼을 만들기 df['pants'] + df['shirts'] df['suits'] = df['pants'] + df['shirts'] df 새로운 열 생성 append() # 새로 추가할 데이터 프레임을 만든다 new_item = [{'bikes':20, 'pants':30, 'watches':35, 'glasses':4}] new_store = pd.DataFrame(data = new_item, index= ['store 3']) new_store # 새로운 데이터인 store 3 를 원래 데이터 df에 추가한다. df =..

Pandas Dataframe 생성 >>> import pandas as pd # 딕셔너리 형태로 만들기 >>> items = {'Bob' : pd.Series(data = [245, 25, 55], index = ['bike', 'pants', 'watch']), 'Alice' : pd.Series(data = [40, 110, 500, 45], index = ['book', 'glasses', 'bike', 'pants'])} >>> df = pd.DataFrame(data= items) >>> df 왼쪽 진한 글자가 인덱스 위쪽 진한 글자는 컬럼 안에 있는 데이터는 밸류 NaN 은 해당 항목에 값이 없음을 뜻한다. (Not a Number) (numpy.nan 과 같다.) >>> df.index I..

Pandas 장점 - Allows the use of labels for rows and columns - 기본적인 통계데이터 제공 - NaN values 를 알아서 처리함. - 숫자 문자열을 알아서 로드함. - 데이터셋들을 merge 할 수 있음. - It integrates with NumPy and Matplotlib Pandas Series 데이터 생성 >>> import pandas as pd >>> index = ['eggs', 'apples', 'milk', 'bread'] >>> data = [30, 6, 'Yes', 'No'] # data로 만들기 >>> x = pd.Series(data = data) >>> x 0 30 1 6 2 Yes 3 No dtype: object # data와,..

1차원 배열 연산 위치에 매치되는 데이터끼리 연산한다. >>> x = np.random.randint(1, 10, 4) >>> y = np.random.randint(10, 100, 4) >>> x array([1, 3, 2, 6]) >>> y array([91, 80, 29, 80]) >>> x + y array([92, 83, 31, 86]) >>> x - y array([-90, -77, -27, -74]) >>> x * y array([ 91, 240, 58, 480]) >>> x / y array([0.01098901, 0.0375 , 0.06896552, 0.075 ]) 2차원 배열 연산 위치에 매치되는 데이터끼리 연산한다. >>> X = np.random.randint(1, 10, (2,2)..

np.unique() -중복된 값을 제거한다. - set과 유사한 기능을 한다. >>> x = np.array([1, 5, 3, 1, 40, 22, 33, 56, 12, 1, 5, 3]) >>> x array([ 1, 5, 3, 1, 40, 22, 33, 56, 12, 1, 5, 3]) >>> np.unique(x) array([ 1, 3, 5, 12, 22, 33, 40, 56])

항목을 끝에 추가하기 np.append() >>> x = np.array([17, 7, 19, 6, 4, 15]) >>> x array([17, 7, 19, 6, 4, 15]) # 끝에 100을 추가하기 >>> np.append(x, 100) array([ 17, 7, 19, 6, 4, 15, 100]) # 끝에 200, 300, 350 추가하기 >>> np.append(x, [200, 300, 350])# 리스트 형태로 추가한다. array([ 17, 7, 19, 6, 4, 15, 200, 300, 350]) # 각 행의 끝에 b 어레이의 요소를 하나씩 추가하기 # append()의 axis = 1로 설정 >>> X = np.array([[36, 66, 62, 17, 50], [58, 47, 6, 45..