Analysis

[데이터마이닝] Lab7-aggregation group by

ialleejy 2024. 12. 5. 09:26

 

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
planets = sns.load_dataset("planets")
planets


<1번 문제> 

행성의 발견 방법에 따른 갯수를 그래프로 그리고 분석

# 1번문제
planets_grouped1 = planets.groupby("method")["number"].sum().reset_index()
plt.figure(figsize=(25, 20))
sns.barplot(data=planets_grouped1, x="method", y="number")

## 1번문제 분석
- 행성발견 방법들 중 Radial Velocity 방법과 Transit 방법이 행성을 찾는데에 있어 주요적으로 많이 사용된 모습을 보인다.
- 두 방법중 Radial Velocity 방법이 Transit 방법보다 대략 150개의 행성을 더 많이 찾아 냈다는 사실을 알 수 있다.

<2번문제>

행은 년도 컬럼은 행성 발견 방법에 따른 평균 궤도 주기를 pivot table을 나타 내고 분석하여라

# 2번문제
planets_pivot = planets.pivot_table(['orbital_period'], index = 'year', columns= 'method')
planets_pivot

 

## 2번문제 분석
- 결측치가 매우 많이 나타나는 모습을 보인다.
- Radial Velocity 방법이 대부분의 년도에서 행성 평균 궤도 주기를 잘 나타낸다는 점을 알 수 있다.
- 그 다음은 Transit 방법이 잘 나타내준다.

 

 


<3번문제>

행성의 발견 방법과 발견년도를 기준으로 평균 거리를 구하고 그중 2011년도 부분만 표시하여 나타내시오.

# 3번문제

planets_grouped3 = planets.groupby(["method", "year"])["distance"].mean().reset_index()
planets_grouped3[planets_grouped['year'] == 2011]

 

 


<4번문제>

3에서 구한행성의 발견 방법과 발견년도를 기준으로 평균 거리로 히트맵으로 표시하시오

# 4번문제
plt.figure(figsize=(10, 6))
sns.heatmap(data=planets_pivot, fmt=".0f" ,annot = True, cmap="YlGn", cbar=True)