SiLaure's Data

[Pandas] 03. DataFrame Method 본문

Records of/Learning

[Pandas] 03. DataFrame Method

data_soin 2021. 7. 25. 22:03

 

- Dataframe 기초 method

 

  • dataframe의 맨 위 다섯 줄을 보여주는 head()
df.head()

출력 : 

 

 

  • 위에서부터 3줄
df.head(3)

출력 : 

 

  • 아래에서부터 3줄
df.tail(3)

출력 : 

 

 

 

 

  • dataframe index
df.index

출력 :

더보기

DatetimeIndex(['2021-01-01', '2021-01-02', '2021-01-03', '2021-01-04',
               '2021-01-05', '2021-01-06'],
              dtype='datetime64[ns]', freq='D')

 

 

  • dataframe columns
df.columns

출력 : Index(['A', 'B', 'C', 'D'], dtype='object')

 

 

  • dataframe values --원소들
df.values

출력 : 

더보기

array([[ 1.00707185,  1.17334531, -0.45291785,  0.28547688], 
       [-1.6643524 ,  1.03865703, -0.64444622,  0.04993952], 
       [-0.73836931,  0.104987  ,  0.76582542,  1.93705806], 
       [ 1.64599863, -0.75431346,  1.01836179,  0.82878258], 
       [ 1.60078327,  0.47679297, -0.40165827, -0.84648856], 
       [ 0.38210713, -1.33423559, -1.03933976,  1.31858381]])

 

 

  • dataframe에 대한 전체적인 요약정보
    --index, columns, null / not-null / dtype / memory usage
df.values

출력 :

더보기

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 6 entries, 2021-01-01 to 2021-01-06
Freq: D
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype  
---  ------  --------------  -----  
 0   A       6 non-null      float64
 1   B       6 non-null      float64
 2   C       6 non-null      float64
 3   D       6 non-null      float64
dtypes: float64(4)
memory usage: 240.0 bytes

 

 

 

  • dataframe에 대한 전체적인 통계정보
df.describe()

출력 :

 

 

column B를 기준으로 내림차순 정렬
df.sort_values(by = 'B')

 

column B를 기준으로 내림차순 정렬 후 Top 3(위에서부터 3줄 자르기)
** method chaining
df.sort_values(by = 'B', ascending=False).head(3)

 

** Q. What is "method chaining" ?
The sequential invocation of methods using the dot notation is referred to as "method chaining".
점 표기법을 사용한 메소드의 순차 호출을 "method chaining"이라고 한다.
즉, 점 찍고 계속 이어서 쓰는 것이 method chainging이다.
Comments