Pandas 입문 2

groupby 집중 연습

라이브러리 불러오기

  • pandas 라이브러리 불러오고, supermarket_sales.csv 파일 불러오기
  • 참고로 미얀마 자료. 얀곤이 옛 수도, 네피도는 현 수도
1
2
import pandas as pd
print(pd.__version__)
1.3.5
1
2
from google.colab import drive
drive.mount('/content/drive') # "/content/drive" 도 가능
Mounted at /content/drive
1
2
3
DATA_PATH = '/content/drive/MyDrive/Colab Notebooks/data/supermarket_sales.csv'
sales = pd.read_csv(DATA_PATH) # 객체를 대문자로 썼는데, 개발자들이 좋아하는 방법이다. 눈에 띄는 걸 좋아한다.
sales

Invoice ID Branch City Customer type Gender Product line Unit price Quantity Date Time Payment
0 750-67-8428 A Yangon Member Female Health and beauty 74.69 7 1/5/2019 13:08 Ewallet
1 226-31-3081 C Naypyitaw Normal Female Electronic accessories 15.28 5 3/8/2019 10:29 Cash
2 631-41-3108 A Yangon Normal Male Home and lifestyle 46.33 7 3/3/2019 13:23 Credit card
3 123-19-1176 A Yangon Member Male Health and beauty 58.22 8 1/27/2019 20:33 Ewallet
4 373-73-7910 A Yangon Normal Male Sports and travel 86.31 7 2/8/2019 10:37 Ewallet
... ... ... ... ... ... ... ... ... ... ... ...
995 233-67-5758 C Naypyitaw Normal Male Health and beauty 40.35 1 1/29/2019 13:46 Ewallet
996 303-96-2227 B Mandalay Normal Female Home and lifestyle 97.38 10 3/2/2019 17:16 Ewallet
997 727-02-1313 A Yangon Member Male Food and beverages 31.84 1 2/9/2019 13:22 Cash
998 347-56-2442 A Yangon Normal Male Home and lifestyle 65.82 1 2/22/2019 15:33 Cash
999 849-09-3807 A Yangon Member Female Fashion accessories 88.34 7 2/18/2019 13:28 Cash

1000 rows × 11 columns

  <script>
    const buttonEl =
      document.querySelector('#df-2c107087-f544-4f62-bedd-767a947c87b5 button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-2c107087-f544-4f62-bedd-767a947c87b5');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
  • 역시 인포부터 알아본다.
1
sales.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 11 columns):
 #   Column         Non-Null Count  Dtype  
---  ------         --------------  -----  
 0   Invoice ID     1000 non-null   object 
 1   Branch         1000 non-null   object 
 2   City           1000 non-null   object 
 3   Customer type  1000 non-null   object 
 4   Gender         1000 non-null   object 
 5   Product line   1000 non-null   object 
 6   Unit price     1000 non-null   float64
 7   Quantity       1000 non-null   int64  
 8   Date           1000 non-null   object 
 9   Time           1000 non-null   object 
 10  Payment        1000 non-null   object 
dtypes: float64(1), int64(1), object(9)
memory usage: 86.1+ KB

Group by

  • (동의어) 집계함수를 배운다.
1
2
3
sales['Invoice ID'].value_counts()
# 송장번호로 그룹화 하기는 어렵겠다...
# 적절한 기준을 찾을 때까지 노가다 해야한다.
750-67-8428    1
642-61-4706    1
816-72-8853    1
491-38-3499    1
322-02-2271    1
              ..
633-09-3463    1
374-17-3652    1
378-07-7001    1
433-75-6987    1
849-09-3807    1
Name: Invoice ID, Length: 1000, dtype: int64
1
2
sales.groupby('Product line')['Quantity'].sum()
# 어떤 칼럼으로 그룹을 지을지 고민해야한다.
Product line
Electronic accessories    971
Fashion accessories       902
Food and beverages        952
Health and beauty         854
Home and lifestyle        911
Sports and travel         920
Name: Quantity, dtype: int64
1
sales.groupby(['Product line', 'Branch', 'Payment'])['Quantity'].sum()
Product line            Branch  Payment    
Electronic accessories  A       Cash            85
                                Credit card    121
                                Ewallet        116
                        B       Cash           134
                                Credit card     83
                                Ewallet         99
                        C       Cash           179
                                Credit card     58
                                Ewallet         96
Fashion accessories     A       Cash            60
                                Credit card     85
                                Ewallet        118
                        B       Cash           110
                                Credit card    100
                                Ewallet         87
                        C       Cash           110
                                Credit card    108
                                Ewallet        124
Food and beverages      A       Cash            78
                                Credit card    114
                                Ewallet        121
                        B       Cash            41
                                Credit card    138
                                Ewallet         91
                        C       Cash           176
                                Credit card     83
                                Ewallet        110
Health and beauty       A       Cash            98
                                Credit card     73
                                Ewallet         86
                        B       Cash           113
                                Credit card     97
                                Ewallet        110
                        C       Cash            82
                                Credit card    104
                                Ewallet         91
Home and lifestyle      A       Cash           139
                                Credit card     85
                                Ewallet        147
                        B       Cash            94
                                Credit card     93
                                Ewallet        108
                        C       Cash            73
                                Credit card     81
                                Ewallet         91
Sports and travel       A       Cash           112
                                Credit card    102
                                Ewallet        119
                        B       Cash           136
                                Credit card     88
                                Ewallet         98
                        C       Cash            76
                                Credit card    109
                                Ewallet         80
Name: Quantity, dtype: int64
  • 여기서 시리즈타입과 데이터프레임타입 구분이 중요하다.
  • 위의 표는 무슨 타입일까?
1
print(type(sales.groupby(['Product line', 'Branch', 'Payment'])['Quantity'].sum()))
<class 'pandas.core.series.Series'>
  • 이게 시리즈 타입이라고?? 시리즈는 인덱스 하나 + 칼럼 하나로 구성된 것이 아니었나…
  • Product line, Branch, Payment 세 개가 함께 인덱스란 소리다.
  • “Multi index”
  • 가장 오른쪽에 나오는 숫자열이 한 개의 칼럼에 해당

시리즈 타입을 데이터프레임 타입으로 바꾸고 싶어

  • 구글링 필요.
  • as_index = False
1
sales.groupby(['Product line', 'Branch', 'Payment'], as_index=False)['Quantity'].sum()

Product line Branch Payment Quantity
0 Electronic accessories A Cash 85
1 Electronic accessories A Credit card 121
2 Electronic accessories A Ewallet 116
3 Electronic accessories B Cash 134
4 Electronic accessories B Credit card 83
5 Electronic accessories B Ewallet 99
6 Electronic accessories C Cash 179
7 Electronic accessories C Credit card 58
8 Electronic accessories C Ewallet 96
9 Fashion accessories A Cash 60
10 Fashion accessories A Credit card 85
11 Fashion accessories A Ewallet 118
12 Fashion accessories B Cash 110
13 Fashion accessories B Credit card 100
14 Fashion accessories B Ewallet 87
15 Fashion accessories C Cash 110
16 Fashion accessories C Credit card 108
17 Fashion accessories C Ewallet 124
18 Food and beverages A Cash 78
19 Food and beverages A Credit card 114
20 Food and beverages A Ewallet 121
21 Food and beverages B Cash 41
22 Food and beverages B Credit card 138
23 Food and beverages B Ewallet 91
24 Food and beverages C Cash 176
25 Food and beverages C Credit card 83
26 Food and beverages C Ewallet 110
27 Health and beauty A Cash 98
28 Health and beauty A Credit card 73
29 Health and beauty A Ewallet 86
30 Health and beauty B Cash 113
31 Health and beauty B Credit card 97
32 Health and beauty B Ewallet 110
33 Health and beauty C Cash 82
34 Health and beauty C Credit card 104
35 Health and beauty C Ewallet 91
36 Home and lifestyle A Cash 139
37 Home and lifestyle A Credit card 85
38 Home and lifestyle A Ewallet 147
39 Home and lifestyle B Cash 94
40 Home and lifestyle B Credit card 93
41 Home and lifestyle B Ewallet 108
42 Home and lifestyle C Cash 73
43 Home and lifestyle C Credit card 81
44 Home and lifestyle C Ewallet 91
45 Sports and travel A Cash 112
46 Sports and travel A Credit card 102
47 Sports and travel A Ewallet 119
48 Sports and travel B Cash 136
49 Sports and travel B Credit card 88
50 Sports and travel B Ewallet 98
51 Sports and travel C Cash 76
52 Sports and travel C Credit card 109
53 Sports and travel C Ewallet 80

  <script>
    const buttonEl =
      document.querySelector('#df-8d1795bd-e055-460d-8f14-0c4e1c3f00d5 button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-8d1795bd-e055-460d-8f14-0c4e1c3f00d5');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
1
print(type(sales.groupby(['Product line', 'Branch', 'Payment'], as_index=False)['Quantity'].sum()))
<class 'pandas.core.frame.DataFrame'>

결측치 다루기

결측치 데이터 생성

  • 임의로 만들기
  • 대부분 딕셔너리 형태
1
2
3
4
5
6
7
8
9
10
import pandas as pd
import numpy as np

dict_01 = {
'Score_A' : [80,90,np.nan,80],
'Score_B' : [30,45,np.nan, np.nan],
'Score_C' : [np.nan, 50,80,90]
}
df = pd.DataFrame(dict_01)
df

Score_A Score_B Score_C
0 80.0 30.0 NaN
1 90.0 45.0 50.0
2 NaN NaN 80.0
3 80.0 NaN 90.0

  <script>
    const buttonEl =
      document.querySelector('#df-cf88f083-c896-4734-b449-7286820b6a16 button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-cf88f083-c896-4734-b449-7286820b6a16');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
1
df.isnull().sum() # 각 컬럼의 결측치 개수
Score_A    1
Score_B    2
Score_C    1
dtype: int64
  • True = 숫자 1로 인식
  • False = 숫자 0으로 인식
1
2
type(df.isnull().sum()) # 중간중간 타입을 확인하는 이유는 시리즈와 데이터프레임 메서드가 다르니까 그런것이다.
# 표 보다는 그래프로 보여주면 더 인식하기 쉽다.
pandas.core.series.Series
1
2
df.fillna("입력값") # "입력값"으로 채우기
# df.fillna("0") -> 0으로 채우기

Score_A Score_B Score_C
0 80.0 30.0 입력값
1 90.0 45.0 50.0
2 입력값 입력값 80.0
3 80.0 입력값 90.0

  <script>
    const buttonEl =
      document.querySelector('#df-a445638e-d7a2-4313-8ad8-ec710da9a067 button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-a445638e-d7a2-4313-8ad8-ec710da9a067');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
1
df.fillna(method="pad") # 결측치 바로 위에 있는 값으로 채우기

Score_A Score_B Score_C
0 80.0 30.0 NaN
1 90.0 45.0 50.0
2 90.0 45.0 80.0
3 80.0 45.0 90.0

  <script>
    const buttonEl =
      document.querySelector('#df-8721f51c-2ef4-419b-8511-8e0a18fd252a button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-8721f51c-2ef4-419b-8511-8e0a18fd252a');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
1
2
3
4
5
6
dict_01 = {
"성별" : ["남자", "여자", np.nan, "남자"],
"Salary" : [30, 45, 90, 70]
}
df = pd.DataFrame(dict_01)
df

성별 Salary
0 남자 30
1 여자 45
2 NaN 90
3 남자 70

  <script>
    const buttonEl =
      document.querySelector('#df-c9256c94-14de-4167-a50f-4ab030334a2d button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-c9256c94-14de-4167-a50f-4ab030334a2d');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
1
df['성별'].fillna("성별 없음") # 성별 칼럼에서만 결측치 원하는 값으로 채우기
0       남자
1       여자
2    성별 없음
3       남자
Name: 성별, dtype: object
  • 결측치

–> 문자열 타입 / 숫자 타입 접근 방법이 다르다.
–> 문자열 (빈도 –> 가장 많이 나타나는 문자열 넣어주기!, 최빈값)
–> 숫자열 (평균, 최대, 최소, 중간, 이상치로 처리, 기타 등등..)

Score_D 결측치 없는 칼럼 추가

1
2
3
4
5
6
7
8
9
10
11
import pandas as pd
import numpy as np

dict_01 = {
'Score_A' : [80,90,np.nan,80],
'Score_B' : [30,45,np.nan, 60],
'Score_C' : [np.nan, 50,80,90],
'Score_D' : [50, 30, 80, 60]
}
df = pd.DataFrame(dict_01)
df

Score_A Score_B Score_C Score_D
0 80.0 30.0 NaN 50
1 90.0 45.0 50.0 30
2 NaN NaN 80.0 80
3 80.0 60.0 90.0 60

  <script>
    const buttonEl =
      document.querySelector('#df-e3909644-07fd-4398-9f80-787495b12866 button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-e3909644-07fd-4398-9f80-787495b12866');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
  • 인덱스1, 3(1행, 3행), D열은 결측치가 없다.
1
2
df.dropna(axis = 1) # axis = 1 은 컬럼기준 # axis = 0 은 인덱스 기준
# 결측치가 있는 컬럼은 없애주겠다.

Score_D
0 50
1 30
2 80
3 60

  <script>
    const buttonEl =
      document.querySelector('#df-4e41ca0e-e4ca-40cc-a91c-14b180a756bf button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-4e41ca0e-e4ca-40cc-a91c-14b180a756bf');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
1
df.dropna(axis = 0) # 결측치가 있는 인덱스(행)은 없애주겠다.

Score_A Score_B Score_C Score_D
1 90.0 45.0 50.0 30
3 80.0 60.0 90.0 60

  <script>
    const buttonEl =
      document.querySelector('#df-7d8b6c36-b63e-46c9-a499-6fd349891ef2 button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-7d8b6c36-b63e-46c9-a499-6fd349891ef2');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>

이상치

1
2
sales

Invoice ID Branch City Customer type Gender Product line Unit price Quantity Date Time Payment
0 750-67-8428 A Yangon Member Female Health and beauty 74.69 7 1/5/2019 13:08 Ewallet
1 226-31-3081 C Naypyitaw Normal Female Electronic accessories 15.28 5 3/8/2019 10:29 Cash
2 631-41-3108 A Yangon Normal Male Home and lifestyle 46.33 7 3/3/2019 13:23 Credit card
3 123-19-1176 A Yangon Member Male Health and beauty 58.22 8 1/27/2019 20:33 Ewallet
4 373-73-7910 A Yangon Normal Male Sports and travel 86.31 7 2/8/2019 10:37 Ewallet
... ... ... ... ... ... ... ... ... ... ... ...
995 233-67-5758 C Naypyitaw Normal Male Health and beauty 40.35 1 1/29/2019 13:46 Ewallet
996 303-96-2227 B Mandalay Normal Female Home and lifestyle 97.38 10 3/2/2019 17:16 Ewallet
997 727-02-1313 A Yangon Member Male Food and beverages 31.84 1 2/9/2019 13:22 Cash
998 347-56-2442 A Yangon Normal Male Home and lifestyle 65.82 1 2/22/2019 15:33 Cash
999 849-09-3807 A Yangon Member Female Fashion accessories 88.34 7 2/18/2019 13:28 Cash

1000 rows × 11 columns

  <script>
    const buttonEl =
      document.querySelector('#df-eadd2087-3f9d-4047-a8f0-8d2fa7572222 button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-eadd2087-3f9d-4047-a8f0-8d2fa7572222');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
  • 일반적인 통계 공식은

  • IQR(Interquartile Range) - 박스플롯 - 사분위수

  • Q0(0), Q1(25%), Q2(50%), Q3(75%), Q4(100%)

  • IQR = Q3 - Q1

  • 이상치의 하한 경계값 : Q1 - (1.5 * (Q3-Q1))

  • 이상치의 상한 경계값 : Q3 + (1.5 * (Q3-Q1))

  • 도메인(각 비즈니스 영역, 미래 일자리)에서 바라보는 이상치 기준(관습)

  • 더 중요한 것은 관습이다.

1
sales[['Unit price']].describe()

Unit price
count 1000.000000
mean 55.672130
std 26.494628
min 10.080000
25% 32.875000
50% 55.230000
75% 77.935000
max 99.960000

  <script>
    const buttonEl =
      document.querySelector('#df-c275e09e-666c-4e82-b6f2-72bbe50e96e4 button.colab-df-convert');
    buttonEl.style.display =
      google.colab.kernel.accessAllowed ? 'block' : 'none';

    async function convertToInteractive(key) {
      const element = document.querySelector('#df-c275e09e-666c-4e82-b6f2-72bbe50e96e4');
      const dataTable =
        await google.colab.kernel.invokeFunction('convertToInteractive',
                                                 [key], {});
      if (!dataTable) return;

      const docLinkHtml = 'Like what you see? Visit the ' +
        '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
        + ' to learn more about interactive tables.';
      element.innerHTML = '';
      dataTable['output_type'] = 'display_data';
      await google.colab.output.renderOutput(dataTable, element);
      const docLink = document.createElement('div');
      docLink.innerHTML = docLinkHtml;
      element.appendChild(docLink);
    }
  </script>
</div>
1
2
3
4
5
6
7
8
9
Q1 = sales['Unit price'].quantile(0.25)
Q3 = sales['Unit price'].quantile(0.75)
outliers_Q1 = Q1 - 1.5 * (Q3-Q1)
outliers_Q1 # -34.~~ 값은 쓰기 어렵다. 이럴 경우에는 임의로 정해준다.
# 이상치의 하한값을 그냥 Q1으로 잡는다.
real_outliers_Q1 = (sales['Unit price'] < Q1)

# 이상치의 상한값을 마찬가지로 Q3로 잡는다.
real_outliers_Q3 = (sales['Unit price'] > Q3)
1
print(sales['Unit price'][~(real_outliers_Q1|real_outliers_Q3)])
0      74.69
2      46.33
3      58.22
6      68.84
7      73.56
       ...  
991    76.60
992    58.03
994    60.95
995    40.35
998    65.82
Name: Unit price, Length: 500, dtype: float64
Author

HS

Posted on

2022-03-27

Updated on

2022-03-26

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.
You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.