728x90
반응형
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 , ['Employee Name', 'Salary [$/h]'] ]
경력이 3년 이하이거나 8년 이상인 사람의 이름을 가져오시오
(df['Years of Experience'] <= 3) | (df['Years of Experience'] >= 8)
my_filter = (df['Years of Experience'] <= 3) | (df['Years of Experience'] >= 8)
df.loc[my_filter,]
데이터 액세스의 부등식을 조합할 때는 그리고 에 해당하는 & 와 또는 에 해당하는 | 를 사용한다
경력이 3년 이상이고, 시급이 30달러 이상인 사람의 데이터를 가져오시오
df.loc[(df['Years of Experience'] >= 3) & (df['Salary [$/h]'] >= 30)]
시급이 가장 높은 사람의 이름과 시급을 가져오시오
시급이 가장 높은 데이터
df['Salary [$/h]'] == df['Salary [$/h]'].max()
df.loc[df['Salary [$/h]'] == df['Salary [$/h]'].max()]
728x90
반응형
'즐거운프로그래밍' 카테고리의 다른 글
[pandas] pandas 실습예제 2 (0) | 2023.11.16 |
---|---|
[pandas] pandas 실습예제 1 (0) | 2023.11.16 |
[pandas] pandas HTML 웹 자료 읽어온 후 데이터 처리 (0) | 2023.11.15 |
[pandas] pandas 파일 읽어온 뒤 데이터 중복 제거와 데이터 처리 예제 (nunique, count, unique, sum, mean, groupby, agg, value_counts) (0) | 2023.11.15 |
[pandas] pandas 파일 읽어온 뒤 데이터 처리하기(describe, head, tail, info) (0) | 2023.11.15 |