본문 바로가기

전체 글153

[Matplotlib] Matplotlib 기본 사용법 Matplotlib 기본 사용법¶ Pyplot 소개¶ matplotlib.pyplot MATLAB과 비슷하게 명령어 스타일로 동작하는 파이썬 시각화 모듈입니다. 기본 그래프¶ In [1]: import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4]) plt.ylabel('y-label') plt.show() In [2]: plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) Out[2]: [] 스타일 지정¶: x, y 값 인자에 대해 그래프 선의 색상과 형태를 지정하는 포맷 문자열을 세번째 인자에 입력할 수 있습니다. In [3]: plt.plot([10, 20, 30, 40], [1, 4, 9, 16], 'rs--') pl.. 2021. 6. 29.
[Pandas] Pandas Cheat Sheet(Group Data) Group Data¶ 그룹 연산(Group by)¶ group by 후에는 다양한 연산을 할 수 있는데, 예시는 다음과 같습니다. size, count: 각 그룹의 수 mean, median, min, max: 각 그룹의 평균, 중앙값, 최소, 최대 sum, prod, std, var, quantile : 각 그룹의 합계, 곱, 표준편차, 분산, 사분위수 first, last: 각 그룹의 가장 첫번째 값과 가장 마지막 값 In [1]: import pandas as pd import seaborn as sns In [2]: df = sns.load_dataset("diamonds") df.head() Out[2]: carat cut color clarity depth table price x y z 0 .. 2021. 6. 24.
[Pandas] Pandas Cheat Sheet(Combine Data Sets) Combine Data Sets¶ In [1]: import pandas as pd In [2]: adf = pd.DataFrame({"x1": ["A", "B", "C"], "x2": [1, 2, 3]}) adf Out[2]: x1 x2 0 A 1 1 B 2 2 C 3 In [3]: bdf = pd.DataFrame({"x1": ["A", "B", "D"], "x3": ["T", "F", "T"]}) bdf Out[3]: x1 x3 0 A T 1 B F 2 D T pd.merge(): 데이터 프레임 합치기¶ how는 데이터를 어떠한 방법으로 합칠지에 관한 옵션입니다. on은 기준이 되는 열을 의미합니다. left¶ 왼쪽 데이터프레임을 기준으로 조입합니다. 오른쪽 데이터프레임에 존해하지 않는 값은 NaN.. 2021. 6. 22.
[Pandas] Pandas Cheat Sheet(Make New Columns) Make New Columns¶ In [1]: import pandas as pd import seaborn as sns import numpy as np In [2]: df = sns.load_dataset("iris") df.head() Out[2]: sepal_length sepal_width petal_length petal_width species 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa 2 4.7 3.2 1.3 0.2 setosa 3 4.6 3.1 1.5 0.2 setosa 4 5.0 3.6 1.4 0.2 setosa 새로운 열 추가¶ 단일 열 추가¶ In [3]: df['all_length'] = df.sepal_length + .. 2021. 6. 21.
[Pandas] Pandas Cheat Sheet(Handling Missing Data) Handling Missing Data¶ In [1]: import pandas as pd import numpy as np In [2]: df = pd.DataFrame([[np.nan, 3, np.nan, 0], [5, 2, 3, 1], [np.nan, np.nan, np.nan, 8], [4, np.nan, 6, 8]], columns=list('ABCD')) df Out[2]: A B C D 0 NaN 3.0 NaN 0 1 5.0 2.0 3.0 1 2 NaN NaN NaN 8 3 4.0 NaN 6.0 8 isna(), notna(): 결측치 여부 확인¶ In [3]: df.isna().sum() Out[3]: A 2 B 2 C 2 D 0 dtype: int64 is.na는 결측치의 .. 2021. 6. 21.
[Pandas] Pandas Cheat Sheet(Summarize Data) Summarize Data¶ In [1]: import pandas as pd import seaborn as sns import numpy as np In [2]: df = sns.load_dataset('iris') df.head() Out[2]: sepal_length sepal_width petal_length petal_width species 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa 2 4.7 3.2 1.3 0.2 setosa 3 4.6 3.1 1.5 0.2 setosa 4 5.0 3.6 1.4 0.2 setosa value_counts¶ In [3]: df['species'].value_counts() Out[3]:.. 2021. 6. 20.