https://www.datamanim.com/dataset/03_dataq/typeone.html#id6
작업 1유형 — DataManim
Question 각 비디오는 10분 간격으로 구독자수, 좋아요, 싫어요수, 댓글수가 수집된것으로 알려졌다. 공범 EP1의 비디오정보 데이터중 수집간격이 5분 이하, 20분이상인 데이터 구간( 해당 시점 전,후
www.datamanim.com
Question
데이터는 2018년도와 2019년도의 전세계 행복 지수를 표현한다.
각년도의 행복랭킹 10위를 차지한 나라의 행복점수의 평균을 구하여라
import pandas as pd
df =pd.read_csv('https://raw.githubusercontent.com/Datamanim/datarepo/main/happy2/happiness.csv',encoding='utf-8')
df.head()

df.shape

result = df[df.행복랭킹 ==10]['점수'].mean()
print(result)

Question
데이터는 2018년도와 2019년도의 전세계 행복 지수를 표현한다.
각년도의 행복랭킹 50위이내의 나라들의 각각의 행복점수 평균을 데이터프레임으로 표시하라
result = df[df.행복랭킹<=50][['년도','점수']].groupby('년도').mean()
print(result)

Question
2018년도 데이터들만 추출하여 행복점수와 부패에 대한 인식에 대한 상관계수를 구하여라
df[df.년도 ==2018][['점수','부패에 대한인식']].corr()

result = df[df.년도 ==2018][['점수','부패에 대한인식']].corr().iloc[0,1]
print(result)

Question
2018년도와 2019년도의 행복랭킹이 변화하지 않은 나라명의 수를 구하여라
df[['행복랭킹','나라명']].drop_duplicates()

result = len(df[['행복랭킹','나라명']]) - len(df[['행복랭킹','나라명']].drop_duplicates())
print(result)

Question
2019년도 데이터들만 추출하여 각변수간 상관계수를 구하고 내림차순으로 정렬한 후 상위 5개를 데이터 프레임으로 출력하라. 컬럼명은 v1,v2,corr으로 표시하라
df[df.년도 ==2019].corr()

df[df.년도 ==2019].corr().unstack()

df[df.년도 ==2019].corr().unstack().to_frame()

df[df.년도 ==2019].corr().unstack().to_frame().reset_index()

zz = df[df.년도 ==2019].corr().unstack().to_frame().reset_index().dropna()
result = zz[zz[0] !=1].sort_values(0,ascending=False).drop_duplicates(0)
answer = result.head(5).reset_index(drop=True)
answer.columns = ['v1','v2','corr']
display(answer)

Question
각 년도별 하위 행복점수의 하위 5개 국가의 평균 행복점수를 구하여라
df.groupby('년도').tail(5)

df.groupby('년도').tail(5).groupby('년도').mean()

result = df.groupby('년도').tail(5).groupby('년도').mean()[['점수']]
print(result)

Question
2019년 데이터를 추출하고 해당데이터의 상대 GDP 평균 이상의 나라들과 평균 이하의 나라들의 행복점수 평균을 각각 구하고 그 차이값을 출력하라
over = df[df.상대GDP >= df.상대GDP.mean()]['점수'].mean()
under = df[df.상대GDP <= df.상대GDP.mean()]['점수'].mean()
result= over - under
print(result)

Question
각년도의 부패에 대한인식을 내림차순 정렬했을때 상위 20개 국가의 부패에 대한인식의 평균을 구하여라
df.sort_values(['년도','부패에 대한인식'],ascending=False)

df.sort_values(['년도','부패에 대한인식'],ascending=False).groupby('년도').head(20).groupby(['년도']).mean()

result = df.sort_values(['년도','부패에 대한인식'],ascending=False).groupby('년도').head(20).groupby(['년도']).mean()[['부패에 대한인식']]
print(result)

Question
2018년도 행복랭킹 50위 이내에 포함됐다가 2019년 50위 밖으로 밀려난 국가의 숫자를 구하여라
result = set(df[(df.년도==2018) & (df.행복랭킹 <=50)].나라명) -set(df[(df.년도==2019) & (df.행복랭킹 <=50)].나라명)
answer = len(result)
print(answer)

Question
2018년,2019년 모두 기록이 있는 나라들 중 년도별 행복점수가 가장 증가한 나라와 그 증가 수치는?
count = df.나라명.value_counts()
count

type(count)

target = count[count>=2].index
target

count = df.나라명.value_counts()
target = count[count>=2].index
df2 =df.copy()
multiple = df2[df2.나라명.isin(target)].reset_index(drop=True)
multiple.loc[multiple['년도']==2018,'점수'] = multiple[multiple.년도 ==2018]['점수'].values * (-1)
result = multiple.groupby('나라명').sum()['점수'].sort_values().to_frame().iloc[-1]
result

'빅데이터분석기사 > 작업 1유형' 카테고리의 다른 글
포켓몬 정보 데이터 (0) | 2022.08.15 |
---|---|
지역구 에너지 소비량 데이터 (0) | 2022.08.15 |
서울시 따릉이 이용정보 데이터 (0) | 2022.08.15 |
월드컵 출전선수 골기록 데이터 (0) | 2022.08.14 |
유튜브 공범 컨텐츠 동영상 데이터 (0) | 2022.08.14 |