π 2. νμ±μ μ¬λ¬κ°μ§ μ 보λ₯Ό μμ보μ(1)
π μ λ² λ―Έκ΅ μΈκ΅¬ λ°μ΄ν° μ΄ν λλ²μ§Έ λ°μ΄ν°λΆμ μ€μ΅ ν¬μ€ν
μ΄λ€.
π μ΄λ²μλ seaborn λΌμ΄λΈλ¬λ¦¬μμ μ 곡νλ planets λ°μ΄ν°μ
μΌλ‘ μ€μ΅μ μ§νν΄λ³Όκ²μ΄λ€.
1. λ°μ΄ν° λΆλ¬μ€κΈ°
import pandas as pd
import seaborn as sns
planets = sns.load_dataset('planets')
planets.shape
>> (1035, 6)
planets.head()
>>
method number orbital_period mass distance year
0 Radial Velocity 1 269.300 7.10 77.40 2006
1 Radial Velocity 1 874.774 2.21 56.95 2008
2 Radial Velocity 1 763.000 2.60 19.84 2011
3 Radial Velocity 1 326.030 19.40 110.62 2007
4 Radial Velocity 1 516.220 10.50 119.47 2009
νμ±μ λ°κ²¬ λ°©λ² / κ°μ / κΆ€λμ£ΌκΈ° / μ§λ / 거리 / λ°κ²¬λ λ λ₯Ό λνλΈ λ°μ΄ν°μμ μ μ μλ€.
planets.info()
>>
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1035 entries, 0 to 1034
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 method 1035 non-null object
1 number 1035 non-null int64
2 orbital_period 992 non-null float64
3 mass 513 non-null float64
4 distance 808 non-null float64
5 year 1035 non-null int64
dtypes: float64(3), int64(2), object(1)
memory usage: 48.6+ KB
orbital_period / mass / distance μ΄μ NaN κ°μ΄ μ‘΄μ¬ν¨μ νμΈν μ μλ€.
νμ§λ§ μ΄ κ°λ€μ λμ€μ μ°λ¦¬κ° μνλ λ°μ΄ν°λ₯Ό μ ννλ κ²½μ°μ μ²λ¦¬ν΄μ£Όλλ‘ νμ.
2. Findnig numbers per method
π κ΄μΈ‘ λ°©λ²μ λ°λΌ λ°κ²¬ν κ°μλ₯Ό μμ보μ.
λ°©λ²μ λ°λΌ λ°κ²¬ν κ°μλ₯Ό μμ보기 μν΄μλ method μ number μ΄μ΄ νμνλ€.
μ΄ λκ°μ μ΄λ§ κ°μ Έμ¨ λ°μ΄ν°λ₯Ό .copy() ν¨μλ₯Ό μ¨μ planets_number λΌκ³ κ°μ Έμ€μ.
planets_number = planets[['method', 'number']].copy()
planets_number λ₯Ό method μ΄μ κΈ°μ€μΌλ‘ κ·Έλ£Ήννκ³ , sum μΌλ‘ μ§κ³ν΄μ£Όμ.
κ°μ₯ λ§μ΄ λ°κ²¬ν λ°©λ² μμΌλ‘ λμ΄νκΈ° μν΄μ .sort_values() ν¨μλ₯Ό μ¬μ©νλ€.
λ΄λ¦Όμ°¨μμ΄λ―λ‘ ascending = False λ₯Ό λ£μ΄μ£Όμ.
planets_number = planets_number.groupby('method').sum().sort_values('number', ascending=False)
planets_number.head()
>>
number
method
Radial Velocity 952
Transit 776
Imaging 50
Microlensing 27
Eclipse Timing Variations 15
2.1. iplot μκ°ν
π λ¨μ λ²μ£Όν λ°μ΄ν°μ΄κΈ° λλ¬Έμ λ° κ·Έλνμ μ κ·Έλνλ‘ μ§κ΄μ μΈ μ°¨μ§μ¨μ μμ보λλ‘ νμ.
import chart_studio.plotly as py
import cufflinks as cf
cf.go_offline(connected = True)
2.1.1. Bar graph
layout = {
'title' : {'text' : '<b>Findnig numbers per method</b>',
'font' : {'size' : 25},
'x' : 0.5, 'y' : 0.9
},
'xaxis' : {'showticklabels' : True,
'title' : {'text' : 'Method', 'font' : {'size' : 20}}},
'yaxis' : {'showticklabels' : True,
'dtick' : '100',
'title' : {'text' : 'numbers', 'font' : {'size' : 20}}}
}
planets_number.iplot(kind = 'bar', theme = 'white', layout = layout)
2.1.2. Pie graph
planets_number_df = planets[['method', 'number']]
planets_number_df.iplot(kind = 'pie', theme = 'white', labels = 'method', values = 'number')
2.2. plotly μκ°ν
import plotly.graph_objects as go
import plotly.offline as pyo
pyo.init_notebook_mode()
2.2.1. Bar graph
fig = go.Figure()
fig.add_trace(
go.Bar(
x = planets_number.index, y = planets_number['number']))
fig.update_layout(
{
'title' : {'text' : '<b>Findnig numbers per method</b>', 'font' : {'size' : 25}, 'x' : 0.5, 'y' : 0.9},
'xaxis' : {'showticklabels' : True, 'title' : {'text' : 'Method', 'font' : {'size' : 15}}},
'yaxis' : {'showticklabels' : True, 'dtick' : 100, 'title' : {'text' : 'Number', 'font' : {'size' : 15}}},
'template' : 'plotly_white'
})
fig.show()
π μμ λ§λκ·Έλνλ₯Ό 보면 νμΈν μ μκ² μ§λ§ Redial Velocity λ€μμΌλ‘ Transitμ΄ κ°μ₯ λ§μ κ΄μΈ‘μΉλ₯Ό 보μ νκ³ μμΌλ©°, κ·Έ μΈμ λλ¨Έμ§ λ°©λ²λ€μ κ·Έλ κ² ν° λΉμ€μ μ°¨μ§νκ³ μμ§λ μμμ νμΈν μ μλ€. μ΄ λ°μ΄ν°λ₯Ό κ°μ₯ μ μ¬μ©ν μ μλ λ°©λ²μ λ λμ κ΄μΈ‘λ°©λ²μ λ°λ₯Έ κ΄μΈ‘μΉλ₯Ό μ 리νλ κ²μ΄λΌκ³ μκ°νλ€.
2.2.2. Pie graph
fig = go.Figure()
fig.add_trace(
go.Pie(
labels = planets_number_df['method'], values = planets_number_df['number']
))
fig.show()
π Pie graphλ₯Ό 보면 μ μ μλ―μ΄ λ무 λ§μ μμλ€μ΄ λ€μ΄κ°λ²λ¦¬λ©΄ κ°λ
μ±μ΄ λ§μ΄ λ¨μ΄μ§λ€.
π λ°λΌμ Pie graphλ₯Ό 그릴 λλ νμν λͺκ°μ§ μμλ§ κ°μ Έμμ μκ°ννλ κ²μ΄ λμ κ²μ΄λΌκ³ μκ°νλ€.
π λ€μ ν¬μ€ν
μμλ ν κ°μ§ κ΄μΈ‘λ°©λ²μλ§ μ§μ€ν΄μ λ°μ΄ν°λ₯Ό μ μ²λ¦¬νκ³ μκ°ννλ λ΄μ©μ λ€λ€λ³΄κ² λ€.
Leave a comment