In [65]:
%matplotlib inline
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [17]:
df = pd.read_csv("iris.csv")
df.info()
In [18]:
df.head()
Out[18]:
In [104]:
sns.set(style="ticks", color_codes=True)
iris = sns.load_dataset("iris")
g = sns.pairplot(iris, hue="species", palette="husl")
In [20]:
iris.info()
In [21]:
df.info()
In [22]:
iris['species'].unique()
Out[22]:
In [23]:
df['species'].unique()
Out[23]:
In [50]:
df.describe(include='all')
Out[50]:
In [51]:
from pandas.api.types import is_numeric_dtype
for col in df.columns:
if is_numeric_dtype(df[col]):
print('%s:' % (col))
print('\t Mean = %.2f' % df[col].mean())
print('\t Standard deviation = %.2f' % df[col].std())
print('\t Minimum = %.2f' % df[col].min())
print('\t Maximum = %.2f' % df[col].max())
In [53]:
df['species'].value_counts()
Out[53]:
In [54]:
print('Covariance:')
df.cov()
Out[54]:
In [55]:
print('Correlation:')
df.corr()
Out[55]:
데이터 시각화
In [74]:
%matplotlib inline
df['sepal_length'].hist(bins=8)
Out[74]:
In [88]:
fig, axes = plt.subplots(2, 2, figsize=(10,6))
index = 0
bins_number=8
for ax1 in range(2):
for ax2 in range(2):
if index == 0 :
axes[ax1][ax2].hist(df['sepal_length'],bins=bins_number)
elif index == 1 :
axes[ax1][ax2].hist(df['sepal_width'],bins=bins_number)
elif index == 2 :
axes[ax1][ax2].hist(df['petal_length'],bins=bins_number)
else:
axes[ax1][ax2].hist(df['petal_width'],bins=bins_number)
axes[ax1][ax2].set_ylabel(df.columns[index])
index += 1
In [89]:
df.boxplot()
Out[89]:
In [95]:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(3, 2, figsize=(10,12))
index = 0
for i in range(3):
for j in range(i+1,4):
ax1 = int(index/2)
ax2 = index % 2
axes[ax1][ax2].scatter(df[df.columns[i]], df[df.columns[j]], color='blue')
axes[ax1][ax2].set_xlabel(df.columns[i])
axes[ax1][ax2].set_ylabel(df.columns[j])
index = index + 1
In [98]:
from pandas.plotting import parallel_coordinates
parallel_coordinates(df, 'species')
Out[98]:
In [101]:
from pandas.plotting import scatter_matrix
scatter_matrix(df, figsize=(8,5))
plt.show()
참조¶
블로그 화면크기에 맞추도록 Jupyter notebook 적용 코드가 아래에 삽입되어 있습니다.
In [106]:
from IPython.core.display import display, HTML
display(HTML("<style>.container {width:100% !important; }</style>"))
'PROGRAM > Python' 카테고리의 다른 글
랜덤뽑기 (0) | 2022.09.01 |
---|---|
Class / lambda식 등 (0) | 2020.09.07 |
jupyter notebook을 tistory에 적용하기 (0) | 2020.07.30 |
class -sample (0) | 2020.04.29 |
Turtle - Example (0) | 2020.04.27 |