LiJell's 성장기

09.python_pandas_arithmetic_method 본문

Bigdata/파이썬_Python

09.python_pandas_arithmetic_method

All_is_LiJell 2022. 1. 2. 22:03
반응형

Modified on Jan 02 2022
# -- coding: utf-8 --
"""
Created on Mon Dec 20 17:05:55 2021

@author: hanju
"""

import numpy as np
from pandas import Series, DataFrame

df1 = DataFrame(np.arange(1,17).reshape(4,4))

dir(df1) # 다양한 기능 확인

df1
#     0   1   2   3
# 0   1   2   3   4
# 1   5   6   7   8
# 2   9  10  11  12
# 3  13  14  15  16
df1.sum(axis=0) # 행별 (서로 다른 행 끼리) 같은 위치값 갖는것 끼리 합
# 0    28
# 1    32
# 2    36
# 3    40
# dtype: int64

df1.sum(axis=1) # 컬럼별 합(서로 다른 열 끼리) 같은 위치값 갖는것 끼리 합
# 0    10
# 1    26
# 2    42
# 3    58
# dtype: int64

df1.iloc[:,0] # Series 에서 뽑은거라 Series
# 0     1
# 1     5
# 2     9
# 3    13
# Name: 0, dtype: int32

df1.iloc[:,0].sum() #28
df1.iloc[:,0].mean() #7.0

df1.iloc[0,0] = np.nan
df1
#       0   1   2   3
# 0   NaN   2   3   4
# 1   5.0   6   7   8
# 2   9.0  10  11  12
# 3  13.0  14  15  16
df1.iloc[:,0].mean() #9.0
# skipna = True (default) 자동으로 NaN 무시하고 연산

평균값(최대 또는 최소) 대치

df1.iloc[:,0].mean()
df1.iloc[:,0].isnull()
# 0     True
# 1    False
# 2    False
# 3    False
# Name: 0, dtype: bool

df1.iloc[:,0][df1.iloc[:,0].isnull()] = df1.iloc[:,0].mean()
# df1.iloc[:,0]에서.isnull 이 있으면 평균값으로 바꿔줘
df1
#       0   1   2   3
# 0   9.0   2   3   4
# 1   5.0   6   7   8
# 2   9.0  10  11  12
# 3  13.0  14  15  16
df1.isnull()
df1[df1.isnull()] # 데이터프레임 전체에서 NaN값 확인
df1[df1.notnull()] # 전체에서 Null값이 아닌것


df1.iloc[:,0].var() # 분산
#10.666666666666666
df1.iloc[:,0].std() # 표준편차
# 3.265986323710904
df1.iloc[:,0].min() # 최소값
# 5.0
df1.iloc[:,0].max() # 최대값
# 13.0
df1.iloc[:,0].median() #중위수
# 9.0

(df1.iloc[:,0] >= 10).sum() # 조건에 만족하는 개수 확인 since True=1이니까 True인 값만 합치면 개수가 됨
반응형

'Bigdata > 파이썬_Python' 카테고리의 다른 글

11.python_pandas_sort  (0) 2022.01.04
10.python_replace_method  (0) 2022.01.03
08.python_pandas_string_method  (0) 2022.01.02
07. Pandas _ Series, DataFrame  (0) 2022.01.01
06.python_str_method  (0) 2021.12.20
Comments