๐ ๋ฐ์ดํฐ ๊ฐ์
๐ฉ Data ๋ถ๋ฌ์ค๊ธฐ
- thousands ๋ช
๋ น์ด
- (,)๋ฅผ ์ฌ์ฉํ๊ณ ์์ด์ ๋ฌธ์๋ก ์ธ์๋ ๊ฐ๋ฅ์ฑ์ด ์๋ค.
- ๋ช ๋ น์ด๋ฅผ ํตํด ์ซ์ํ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์จ๋ค.
๐ฉ Data Check
- info() ๋ช ๋ น์ด๋ฅผ ํตํด ๋ฐ์ดํฐ ํ์ธ
- Rangeindex๋ฅผ ๋ณด๋ ์ด 65534๊ฐ์ ๋ฐ์ดํฐ๊ฐ ์๋ค, ํ์ธ์ด ํ์!
- unique() ํจ์๋ฅผ ์ด์ฉํด ํ์ธ, NaN ๋ฐ์ดํฐ ํ์ธ
- DataFrame.isnull() ํจ์๋ก ํ์ธํด๋ณด๋ NaN ๋ฐ์ดํฐ๊ฐ ๋ง๋ค.
- ์ด๋ฅผ notnull() ํจ์๋ก ์ ๊ฑฐ, ๋ฐ์ดํฐ๊ฐ ์ ๋ฆฌ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค
๐ฉ pivot_table()
- index, columns, values, aggfunc
- margin=True : ์ด๊ณ๋ฅผ ํ์
- fill_value : NaN data๋ฅผ ์ฑ์์ค๋ค
- pivot_table() ํจ์๋ฅผ ์ด์ฉ, index๋ก ์ค์ ํ column์ ์ง์ (Name)
- multi index ์ค์
- ๋ฆฌ์คํธ ์์ column name์ ์์ฑ
- ์ค์ต try!
- ์ซ์ ๋ฐ์ดํฐ๋ฅผ pivot_table ์ง์ ํ๋ฉด, ์๋์ผ๋ก ํ๊ท ๊ฐ์ผ๋ก pivot
- aggfunc=np.sum ํจ์๋ก Price ๊ฐ์ ํฉ์ฐ์ฐ์ผ๋ก ์ ์ฉ
- index, values, columns
- Product๋ฅผ ์ปฌ๋ผ์ผ๋ก ์ค์
- NaN data ์ฒ๋ฆฌ ํ์
- fill_value๋ก NaN data๋ฅผ 0์ผ๋ก ์ฒ๋ฆฌ
- 2๊ฐ ์ด์์ values ๊ฐ ์ค์
- aggfunc 2๊ฐ ์ด์ ์ค์
- margins = True๋ฅผ ํตํด ์ด๊ณ ๊ฐ ์ถ๊ฐ
๐ ์์ธ์ ๋ฒ์ฃ ํํฉ ๋ฐ์ดํฐ ์ ๋ฆฌ
๐ฉ pivot_table ํตํด ๋ฐ์ดํฐ ์ ๋ฆฌํ๊ธฐ
- index = ๊ตฌ๋ถ, columns = ์ฃ์ข , ๋ฐ์๊ฒ๊ฑฐ
- ์ง์ญ๊ตฌ(์)๋ฅผ index๋ก ์ง์ ํ์ฌ ๋ฐ์ดํฐ ์ ์
- ๋ฉํฐ์ปฌ๋ผ์ธ ๊ฒ์ ํ์ธ
๐ฉ ๋ค์ค ์ปฌ๋ผ์์ ํน์ ์ปฌ๋ผ์ ์ ๊ฑฐํ๋ ์๋ก์ด ๋ฐฉ๋ฒ
- data_name.columns.droplevel([n1, n2])
- ์ ๋ฆฌ๋ Data ์ถ๋ ฅ
๐ฉ Pip ๋ช ๋ น์ผ๋ก ํ์ํ ๋ชจ๋์ ์ค์น
- !pip list ๋ช ๋ น์ด๋ก ์ค์น๋์ด์๋ ๋ชจ๋์ ํ์ธํ ์ ์๋ค
๐ฉ Google Maps API ์ค์น
- googlemaps๋ฅผ import
- googlemaps.Client(key="ํค ๊ฐ")
- geocode ํจ์๋ฅผ ์ด์ฉํ์ฌ ๊ตฌ๊ธ๋งต ๋ฐ์ดํฐ ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค
- geocode ํจ์์ ๊ธธ์ด๋ 1๋ก ๋ฐํ๋๋ค
- tmp ๋ณ์์ ๋ด์ ๋ค 0๋ฒ์งธ index ๋ฐ์ดํฐ๋ฅผ ํ์ธ
- get ํจ์๋ก ๋ฐ์ดํฐ๋ฅผ ์์นญ
- ์๋์ ๊ฒฝ๋ ๋ฐ์ดํฐ๋ฅผ ์ป์ ์ ์๋ค
- ์ฃผ์ ๋ฐ์ดํฐ ์์นญ
- split์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ฌ๋ผ์ด์ฑ
๐ฉ iterrows() ํจ์
- Pandas DataFrame์ ๋๋ถ๋ถ 2์ฐจ์ ๋ฐ์ดํฐ
- Pandas DataFrame์ผ๋ก ๋ฐ๋ณต๋ฌธ์ ๋ง๋ค ๋, iterrows ํจ์๋ฅผ ์ฐ๋ฉด ํธํ๋ค
- index, rows ๋ฐ์ดํฐ๋ฅผ ๋ฐํ
- station_name์ ๋ณ์๋ฅผ ์ค๋ค.
- ๊ตฌ๊ธ๋งต์ ๊ฒฝ์ฐฐ์ ์ด๋ฆ์ ๊ฒ์ํ๋ฉด ์๋์ ๊ฒฝ๋, ์ฃผ์ ๋ฐ์ดํฐ๊ฐ ๋ฐํ๋๋ ๊ฒ์ ์ด์ฉ ๋์ค๋ ๊ฒ์ ์ด์ฉํ์ฌ
๊ฐ ๊ฒฝ์ฐฐ์์ ์์น์ ์๋, ๊ฒฝ๋๋ฅผ ์ถ์ถํ๋ค.
๐ฉ ๋ฐ์ดํฐ ์ปฌ๋ผ ์ ๋ฆฌํ๊ธฐ
- data_name.columns.get_level_values ํจ์ ์ฌ์ฉ
- ๊ฐ ๋ฐ์ดํฐ ์ปฌ๋ผ๋ค์ ๊ฐ์ ๊ตฌํด์ค๋ค
- ๊ฐ ์ปฌ๋ผ์ for๋ฌธ์ ํตํด์ ํฉ์ณ์ค ํ, ์ ์ฅ
๐ฉ ๊ตฌ๋ณ ๋ฐ์ดํฐ๋ก ์ ๋ฆฌ
- ๊ตฌํ๋ DataFrame ํ์ธ ํ index_col ์ต์ ์ผ๋ก ๊ตฌ๋ถ ๋ฐ์ดํฐ๋ฅผ index๋ก ๋ฐ๊ฟ์ค๋ค.
- ๊ฒฝ์ฐฐ์ ์ด๋ฆ ๋ฐ์ดํฐ๋ฅผ ๊ตฌ๋ณ ๋ฐ์ดํฐ๋ก ์ ๋ฆฌ
- ํ์์๋ ์ปฌ๋ผ ์ ๊ฑฐ (lat, lng)
๐ฉ ๋ค์์ ์ปฌ๋ผ์ ๋๋๊ธฐ
- data_frame[["column1", "column2"]].div(data_frame["column3"], axis = 0) #axis = 0 : ๊ฐ๋ก
- divํจ์๋ก ๋ค์์ ์ปฌ๋ผ์ ๋๋ ์ ์๋ค
- ๊ฐ ์ปฌ๋ผ์ ๋๋ ์ฃผ์ด ํ๋ฅ ์ ๊ณ์ฐํ๋ค.
- ๊ฐ ์ปฌ๋ผ์ ๊ฐ์ด 100์ด ๋์ด๊ฐ๋ ๋ฐ์ดํฐ๋ 100์ผ๋ก ํต์ผ์์ผ์ค๋ค
- rename ํจ์๋ฅผ ์ด์ฉํ์ฌ ์ปฌ๋ผ ์ด๋ฆ์ ์ฌ์ ๋นํ๋ค.
๐ฉ ๋ฒ์ฃ ๋ฐ์ดํฐ ์ ๋ ฌ์ ์ํ ๋ฐ์ดํฐ ์ ๋ฆฌ (์ ๊ทํ)
- ์ ๊ทํ : ์ต๊ณ ๊ฐ์ 1, ์ต์๊ฐ์ 0
- ๊ธฐ์กด์ ์ปฌ๋ผ๋ฐ์ดํฐ๋ฅผ ์ปฌ๋ผ ๋ฐ์ดํฐ ๋ด์ ์ต๋๊ฐ์ผ๋ก ๋๋ ๊ฐ
- ์ ๊ทํ๋ ๋ฐ์ดํฐ์ ๊ฐ ์ฃ์ข ์ ๊ฒ๊ฑฐ์จ ์ปฌ๋ผ ๋ฐ ์ธ๊ตฌ์, CCTV(์๊ณ) ์ปฌ๋ผ์ถ๊ฐ
- ์ ๊ทํ๋ ๋ฒ์ฃ๋ฐ์ ๊ฑด์ ์ ์ฒด ํ๊ท ์ ๋ฒ์ฃ ์ปฌ๋ผ์ ์ถ๊ฐ
๐ฉ np.mean()
- np.array, np.mean()
- npํจ์์์๋ axis=1 : ํ / axis=0 : ์ด (pandas ํจ์์๋ ๋ฐ๋)
- 2์ฐจ์ ํ๋ ฌ
๐ฉ np ํจ์๋ฅผ ์ด์ฉํด์ ๊ฒ๊ฑฐ์จ ํ๊ท ๊ตฌํ๊ธฐ
๐ฉ seaborn ๊ธฐ์ด
- np.linspace(a, b, s) = a๋ถํฐ b๊น์ง s๊ฐ์ ๋ฑ๊ฐ๊ฒฉ ๋ฐ์ดํฐ ์์ฑ
- sin ํจ์ ๋ง๋ค์ด๋ณด๊ธฐ
- seaborn ํจ์ ์ด์ฉํ์ฌ ๊ทธ๋ํ ์ปค์คํ
- sns.set_style()
- ์์๋๋ก "white", "dark" , "grid",. "darkgrid"
๐ฉ seaborn ๋ฐ์ดํฐ๋ก ๋ค์ํ ๊ทธ๋ํ ๋ง๋ค์ด๋ณด๊ธฐ
๐ฉ boxplot
- boxplot hue (์นดํ ๊ณ ๋ฆฌ๋ฅผ ํํํ๋ ์ต์ )
- palette = "Set 1~3" (ํ๋ ํธ ์ต์ )
๐ฉ swarmplot
๐ฉ lmplot
- lmplot ์์ ํจ์ height(size)๋ฅผ ๋ฃ์ ์ ์๋ค
๐ฉ heatmap
- pivot
- index, columns, values
- heatmap(data, annot, fmt)
- annot=True : ๋ฐ์ดํฐ ๊ฐ ํ์
- fmt = "d" ์ ์ํ์ผ๋ก ํํ, # "f" ์ค์ํ๋ก๋ ๊ฐ๋ฅ
- colormap (cmap)
๐ฉ pairplot
- ์ ์ฒด์ ์ธ ๋ฐ์ดํฐ๋ฅผ ๋ค ๋ณด์ฌ์ค๋ค
- ์ํ๋ ์ปฌ๋ผ๋ง pairplot์ผ๋ก ํํํ ์ ์๋ค.
๐ฉ lmplot
- order option
- outlier
- robust ์ต์ ์ผ๋ก ์์ธ ๋ฐ์ดํฐ๋ฅผ ์ ์ธํ๊ณ ์ถ๋ ฅ
๐ฉ ์์ธ์ ๋ฒ์ฃํํฉ ๋ฐ์ดํฐ ์๊ฐํ
- vars = x,y ๊ฐ ๋ฐ์ดํฐ๋ฅผ ํตํฉ์ ์ผ๋ก ์ถ๋ ฅ
- x_vars, y_vars ๊ฐ ์ถ๋ ฅ
๐ฉ heatmap์ผ๋ก ์๊ฐํํ๊ธฐ
๐ฉ folium.Map()
- location=[lat, lng]
- zoom_start, zoom_control
- tiles option
- folium.Marker(location=[lat, lng]).add_to(m)
- popup (ํด๋ฆญ์ ๋์ค๋ ์ฐฝ)
- tooltip option (๋ง์ฐ์ค ์ปค์๊ฐ ๋ฟ์ผ๋ฉด ๋์ค๋ ์ฐฝ)
- tooltip option, hyperlink ์ฌ์ฉ ๊ฐ๋ฅ
- folium.Icon(color, icon, icon_color, prefix, angle)
- ์์ด์ฝ์ ๋ง์๋๋ก ์ปค์คํ ํ ์ ์๋ค
- folium.ClickForMarker()
- ์ง๋์์ ๋ง์ฐ์ค ํด๋ฆญ์ ๋ง์ปค๋ฅผ ์์ฑ
- folium.LatLngPopup()
- ์ง๋ ์์น ํด๋ฆญ์ ์๋์ ๊ฒฝ๋ ์ ๋ณด ๋ฐํ
- folium.Circle()
- location, radius, fill, color, fill_color, popup, tooltip
- folium.CircleMarker()
- location, radius, fill, color, fill_color, popup, tooltip
๐ฉ ๊ฒฝ์ฐฐ์ ์์น ๋ง์ปค ํ์
- iterrows ํจ์๋ฅผ ์ฌ์ฉ
- rows์ lat, lng ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์์น๋ฅผ ํ์
๐ฉ Choropleth ํจ์
- ์์ ๋์ด๊ฐ ํด์๋ก ๊ฒ๊ฑฐ์จ์ด ๋์ ๊ณณ
'Study_note(zb_data) > EDA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์คํฐ๋ ๋ ธํธ (BeautifulSoup Web data 1) (0) | 2023.08.11 |
---|---|
์คํฐ๋ ๋ ธํธ (BeautifulSoup basic) (0) | 2023.08.11 |
์คํฐ๋ ๋ ธํธ (Analysis Seoul CCTV with population) (0) | 2023.08.06 |
์คํฐ๋ ๋ ธํธ (EDA) ๋ฐ์ดํฐ ํฉ์น๊ธฐ, matplotlib ๊ธฐ์ด (0) | 2023.08.05 |
์คํฐ๋ ๋ ธํธ (EDA) Pandas ๊ธฐ์ด (0) | 2023.08.05 |