새벽코딩

[빅데이터분석기사] 실기 기출문제 4회 작업형 1 본문

데이터분석

[빅데이터분석기사] 실기 기출문제 4회 작업형 1

J 코딩 2024. 6. 21. 17:25
반응형

https://www.datamanim.com/dataset/practice/ex4.html

 

1-1

import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/Datamanim/datarepo/main/krdatacertificate/e4_p1_1.csv')
df.head(5)

Temperature컬럼에서 숫자가 아닌 문자들을 제거후 숫자 타입으로 바꾸고 3분위수에서 1분위수의 차이를 소숫점 이하 2자리까지 구하여라

df.Temperature = df.Temperature.str.replace('*', '')
Q1 = df['Temperature'].quantile(0.25)
Q3 = df['Temperature'].quantile(0.75)
ans = round(Q3-Q1, 2)
print(ans)

 

1-2

import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/Datamanim/datarepo/main/krdatacertificate/e4_p1_3.csv')
df.head(5)

 

Likes를 Comments로 나눈 비율이 20이상이면서 Keyword값이 minecraft인 영상들의 Views값의 평균을 정수로 구하여라

# Likes / Comments
df['r1'] = df['Likes'] / df['Comments']
ans = df.loc[(df.r1 >= 20) & (df.Keyword == 'minecraft'), 'Views'].mean().astype('int')
print(ans)

 

1-3

import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/Datamanim/datarepo/main/krdatacertificate/e4_p1_3.csv')
df.head(5)

date_added가 2018년 1월 이면서 country가 United Kingdom 단독 제작인 데이터의 갯수

 

풀이 1 (str.split)

df2 = df.loc[(df['date_added'].str.split().str[0] == 'January') & (df['date_added'].str.split().str[2] == '2018')]
print(df2.loc[df2.country == 'United Kingdom'].shape[0])

풀이 2 (to_datetime)

df['date'] = pd.to_datetime(df['date_added'].str.strip(), format='%B %d, %Y')
df2 = df.loc[(df['date'].dt.strftime('%Y-%m') == '2018-01') & (df['country'] == 'United Kingdom')]

print(df2.shape[0])

 

감사합니다.

반응형
Comments