[1차 프로젝트] 데이터 전처리
A. Spotify data 데이터 정리하기
- 우선 podcast 관련 열은 사용하지 않을 것임으로 해당 열을 삭제한다.
df = df.drop(columns= ['pod_lis_frequency'
,'fav_pod_genre'
,'preffered_pod_format'
,'pod_host_preference'
,'preffered_pod_duration'
,'pod_variety_satisfaction'])
df.info()
- 'music_recc_rating'을 제외하고 모두 object type로 통일하였다.
B. 결측치 처리하기
- 결측치가 있는 ' preffered_premium_plan ' 열을 살펴보자
- ' preffered_premium_plan ' 열은 구독을 했거나 구독을 할 의향이 있는 사람들에게 얼마를 지불할 것인가에 대한 수치이다.
df.value_counts('preffered_premium_plan', dropna=False, normalize=True)
![]() |
![]() |
- NaN 값이 40%로 데이터 대부분의 자리를 차지하고 있다.
- 이 값은 구독을 취소하거나 구독하지 않을 사용자임을 의미하는 것인지, 선택하지 않은 것인가에 대한 구분이 필요하다.
- NaN값이 어떤 의미인지를 알아볼 필요가 있다.
df.value_counts('spotify_subscription_plan', dropna=False)
df.value_counts('premium_sub_willingness', dropna=False)
![]() |
![]() |
- 'spotify_subscription_plan' : 현재 어떤 Spotify 구독 계획을 갖고 있는가
- 'premium_sub_willingness' : 프리미엄 구독을 하겠는가 혹은 앞으로도 프리미엄 구독을 계속할 의향이 있는가
용어 정리 및 가정
- 구독 중인 사용자: 총 사용자 중 구독중인 사용자를 의미한다.
- 구독 의향이 있는 사용자 : 신규 구독을 하거나 계속 구독할 의향이 있는 사용자를 포함하여 의미한다.
▷ 무료 사용자 424 명 중 일부는 구독 의향이 있을 수 있다고 가정함
▷ 유료 사용자 96명은 모두 구독 중인 사용자로 가정함
1) 구독 중인 사용자 = 96명
2) 신규 구독을 하거나 계속 구독을 이어나갈 의향이 있는 사용자 = 186명
3) 구독을 하였거나 구독할 사용자 = 구독 중인 사용자 + 구독 의향이 있는 사용자 = 96명 + 186명 = 312명
☆ 구독 중인 사용자는 유료 사용자로만 고려함
☆ 무료 사용자 중 구독 의향이 있는 사용자만 포함하여 계산
4) 구독을 취소하거나 구독하지 않을 사용자 = 전체 사용자 - 구독을 하였거나 구독할 사용자 = 520명 - 312명 = 208명
결론
NaN 값과 구독을 취소하거나 구독하지 않을 사용자 값과 같다.
∴ NaN = 구독을 취소하거나 구독하지 않을 사용자 수
df['preffered_premium_plan'] = df['preffered_premium_plan'].fillna('No')
- 결측치가 있는 열은 ' preffered_premium_plan ' 전체 결측치에 'No' 문자값을 넣었다.
C. 이상치 확인하기
- 해당 데이터는 문자열로 구성되어 있다.
- 문자형 값을 고유한 수치로 변환하는 방법에 대해 숙지하지 못하여 열의 값을 모두 확인하는 방법으로 이상치를 확인하였다.
for column in df.columns:
print(df[column].value_counts())
print("\n")
각 컬럼별 값 확인
Age
20-35 422
12-20 71
35-60 23
6-12 3
60+ 1
Name: count, dtype: int64
Gender
Female 391
Male 114
Others 15
Name: count, dtype: int64
spotify_usage_period
More than 2 years 169
1 year to 2 years 141
6 months to 1 year 119
Less than 6 months 91
Name: count, dtype: int64
spotify_listening_device
Smartphone 300
Computer or laptop 54
Smartphone, Computer or laptop 48
Smart speakers or voice assistants 43
Computer or laptop, Smart speakers or voice assistants 14
Smartphone, Smart speakers or voice assistants 10
Smartphone, Wearable devices 8
Smartphone, Computer or laptop, Smart speakers or voice assistants, Wearable devices 8
Wearable devices 8
Smartphone, Computer or laptop, Smart speakers or voice assistants 7
Smartphone, Computer or laptop, Wearable devices 5
Computer or laptop, Wearable devices 5
Smartphone, Smart speakers or voice assistants, Wearable devices 5
Computer or laptop, Smart speakers or voice assistants, Wearable devices 3
Smart speakers or voice assistants, Wearable devices 2
Name: count, dtype: int64
spotify_subscription_plan
Free (ad-supported) 424
Premium (paid subscription) 96
Name: count, dtype: int64
premium_sub_willingness
No 334
Yes 186
Name: count, dtype: int64
preffered_premium_plan
No 208
Individual Plan- Rs 119/ month 95
Student Plan-Rs 59/month 94
Duo plan- Rs 149/month 84
Family Plan-Rs 179/month 39
Name: count, dtype: int64
preferred_listening_content
Music 410
Podcast 110
Name: count, dtype: int64
fav_music_genre
Melody 259
classical 87
Pop 85
Rap 55
Electronic/Dance 16
All 6
Rock 4
Kpop 4
Classical & melody, dance 2
Old songs 1
trending songs random 1
Name: count, dtype: int64
music_time_slot
Night 312
Afternoon 117
Morning 91
Name: count, dtype: int64
music_Influencial_mood
Relaxation and stress relief 195
Uplifting and motivational 67
Sadness or melancholy 55
Relaxation and stress relief, Uplifting and motivational 44
Relaxation and stress relief, Uplifting and motivational, Sadness or melancholy, Social gatherings or parties 35
Relaxation and stress relief, Sadness or melancholy 33
Relaxation and stress relief, Uplifting and motivational, Sadness or melancholy 22
Social gatherings or parties 16
Relaxation and stress relief, Uplifting and motivational, Social gatherings or parties 14
Relaxation and stress relief, Social gatherings or parties 13
Uplifting and motivational, Sadness or melancholy 12
Relaxation and stress relief, Sadness or melancholy, Social gatherings or parties 8
Uplifting and motivational, Social gatherings or parties 4
Sadness or melancholy, Social gatherings or parties 1
Uplifting and motivational, Sadness or melancholy, Social gatherings or parties 1
Name: count, dtype: int64
music_lis_frequency
While Traveling 111
leisure time 87
While Traveling, leisure time 65
While Traveling, Workout session, leisure time 48
Workout session 33
Study Hours 19
Office hours 16
While Traveling, Workout session 16
Office hours, While Traveling 12
Office hours, While Traveling, leisure time 12
Office hours, While Traveling, Workout session 10
Study Hours, While Traveling, leisure time 10
Study Hours, While Traveling 9
Office hours, Study Hours, While Traveling, Workout session, leisure time 7
Study Hours, While Traveling, Workout session 7
Office hours, Study Hours, While Traveling 7
Study Hours, Workout session 6
Office hours, leisure time 6
Workout session, leisure time 6
Study Hours, While Traveling, Workout session, leisure time 4
Study Hours, Workout session, leisure time 4
Study Hours, leisure time 4
Office hours, While Traveling, Workout session, leisure time 3
Office hours, Study Hours, While Traveling, leisure time 3
Office hours, Workout session 3
Office hours, While Traveling, 2
Office hours, Study Hours, Workout session 2
While Traveling, Workout session, leisure time, Night time, when cooking 1
Social gatherings 1
Random 1
Office hours, Workout session, leisure time 1
While Traveling, Before bed 1
Office hours, Study Hours, While Traveling, Workout session 1
Office hours, Study Hours, While Traveling, Workout session, leisure time, 1
Office hours,Study Hours, While Traveling, leisure time 1
Name: count, dtype: int64
music_expl_method
recommendations 113
Playlists 112
recommendations, Playlists 86
Others 55
Radio 51
Playlists, Radio 18
recommendations, Playlists, Others 18
recommendations, Others 15
recommendations, Playlists, Radio 13
Playlists, Others 9
Radio, Others 7
recommendations, Radio 6
Playlists, Radio, Others 6
recommendations, Radio, Others 4
recommendations, Playlists, Radio, Others 2
recommendations,Others, Social media 1
Others, Social media 1
Others, Friends 1
recommendations, Others, Social media 1
Others, Search 1
Name: count, dtype: int64
music_recc_rating
3 190
4 174
5 86
2 56
1 14
Name: count, dtype: int64
- 'Age' 칼럼의 6-12 범위, 60+ 범위값을 이상치라 둔다.
- Spotify 일반적으로 성인(18세 이상)을 대상으로 하는 서비스이다.
- 6~12세의 경우, 부모와 함께 사용할 수도 있지만 값의 개수가 3개이고, 그 비율이 높지 않으므로 이상치로 본다.
- 60세 이상의 사용자가 극소수라는 점에서 이상치로 분류하였다.
df.drop(df[df['Age'].isin(["6-12", "60+"])].index, inplace=True)
- 이상치 제거를 통해 아래와 같이 칼럼이 변경되었다.
D. 최종 데이터 info()