728x90
반응형

pandasData 6

[pandas] pandas SORTING AND ORDERING

경력 오름차순으로 정렬하세요 df['Years of Experience'].sort_values() # 해당 컬럼만 정렬 df.sort_values('Years of Experience') 경력 내림차순으로 정렬하세요 df.sort_values('Years of Experience',ascending=False) length 컬럼을 내림차순으로 정렬하세요 df.sort_values('length', ascending=False) 정렬 조건이 두개 이상일 경우 정렬 방법 length를 내림차순으로 정렬하되, 숫자가 같으면 이름을 오름차순으로 정렬하세요 df.sort_values(['length','Employee Name'], ascending=[False, True])

[pandas] pandas APPLYING FUNCTIONS

직원 이름이 몇글자인지 글자수를 세어서 새로운 컬럼 length를 만드세요 df['Employee Name'].str.len() df['length'] = df['Employee Name'].str.len() df 시급이 30 이상이면, 'A'그룹이라 하고, 시급이 30보다 작으면 'B'그룹이라고 함 (조건문) 새로운 컬럼 group을 만들어서 저장하세요 df['Salary [$/h]'] 함수 만드는 순서 1. 함수의 호출부분을 먼저 작성한다. 2. 호출부분을 참고하여 함수를 정의한다. def grouping(Salary): # 함수만들기 : def if Salary >= 30: return 'A' else: return 'B' df['group'] = df['Salary [$/h]'].apply(gro..

[pandas] pandas 실습예제 2

import pandas as pd reviews = pd.read_csv('/content/drive/MyDrive/Notebooks/data/wine-data.csv',index_col=0) reviews 인덱스를 title 컬럼으로 셋팅한다. reviews.set_index('title', inplace=True) # inplace=True inplace:해당 장소에의 의미, 메모리에서 작업(반영) reviews 먼저 데이터가 비어있느것이 있는지 확인한다. reviews.isna() reviews.isna().sum() 그리고나서, 가격이 없는 데이터는 빼고, 데이터셋을 가져온다. reviews['price'].notna() # notna : true = 가격이 있음 reviews = reviews..

[pandas] pandas 실습예제 1

구글 코랩에 구글 드라이브 마운트 후 csv 파일을 불러옵니다. import pandas as pd reviews = pd.read_csv('/content/drive/MyDrive/Notebooks/data/winemag-data.csv',index_col=0) # index_col = 인덱스로 사용할 컬럼 선택(컬럼 번호로 작성) reviews 리뷰의 디스크립션 컬럼을 desc 로 저장한다. desc = reviews['description'] first_description 이라는 변수에는, 디스크립션 컬럼의 첫번째 데이터를 저장한다. first_description = reviews['description'][0] reviews.loc[0,'description'] reviews.iloc[0, 1..

[pandas] pandas 데이터 가공 연습하기

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 경력이 3년 이상인 사람의 데이터를 가져오시오 df['Years of Experience'] >= 3 df.loc[df['Years of Experience'] >= 3 , ] #변수명.loc[행, 열] # 이 방법은 안된다(에러남) df.iloc[,] 경력이 3년 이상인 사람의 이름과 시급을 가져오시오 df.loc[df['Years of Experience'] >= 3 , ['Emp..

728x90
반응형