작업 1유형 : 포켓몬 정보

SOOYEON·2022년 6월 24일
0

빅데이터분석기사

목록 보기
34/36

포켓몬 정보

Q1. 🌟

Attack컬럼의 값을 기준으로 내림차순정렬 했을때 상위 400위까지 포켓몬들과 401~800위까지의 포켓몬들에서 전설포켓몬(Legendary컬럼)의 숫자 차이는?

# s
att = df.sort_values('Attack',ascending=False).reset_index(drop=True)
res = att[:401][att['Legendary']==True]['Legendary'].count() - att[401:801][att['Legendary']==True]['Legendary'].count()

sum()

up = df.sort_values('Attack',ascending=False).reset_index(drop=True)[:400]
down = df.sort_values('Attack',ascending=False).reset_index(drop=True)[400:]

result = up.Legendary.sum() - down.Legendary.sum()
print(result)

Q2.

Type 1 컬럼의 종류에 따른 Total 컬럼의 평균값을 내림차순 정렬했을때 상위 3번째 Type 1은 무엇인가?

df.groupby('Type 1')['Total'].mean().sort_values(ascending=False).index[2]

Q3.🌟

결측치가 존재하는 행을 모두 지운 후 처음부터 순서대로 60% 데이터를 추출하여 Defense컬럼의 1분위수를 구하여라

# s
 df.dropna()[:int(len(df.dropna())*0.6)]['Defense'].quantile(q=0.25)

Q4.🌟

Type 1 컬럼의 속성이 Fire인 포켓몬들의 Attack의 평균 이상인 Water속성의 포켓몬 수를 구하여라

fa = df[df['Attack'] >= df[df['Type 1']=='Fire']['Attack'].mean()]
len(fa[fa['Type 1']=='Water']) 
# or .shape[0]

Q5.🌟

각 세대 중(Generation 컬럼)의 Speed와 Defense 컬럼의 차이(절댓값)이 가장 큰 세대는?

abs(df.groupby('Generation')[['Speed', 'Defense']].mean().diff(axis=1)).sort_values('Defense',ascending=False).index[0]

#
result = abs(df.groupby(['Generation'])[['Speed','Defense']].mean().T.diff().T).sort_values('Defense').index[-1]
print(result)

0개의 댓글