본문 바로가기

코딩으로 익히는 Python/Pandas

[Python] 10. pandas DataFrame 속성 : ndim, shape, len(), size, T, index, keys(), columns, values, dtypes, info() 예제

728x90
반응형
SMALL
import pandas as pd
import numpy as np

 

data =  {'eng':[10,30,50,70],
         'kor':[20,40,60,80],
         'math':[90,50,20,70]}
df = pd.DataFrame(data, index=['a','b','c','d'] )
df


df.ndim #몇차원
[OUT] :

2

 

df.shape #(행, 열)
[OUT] :

(4, 3)

 

df.shape[0] #행의 갯수
[OUT] :

4

 

len(df) #행의 갯수
[OUT] :

4

 

df.size #데이터의 갯수
[OUT] :

4

 

df.T

 

df.index
[OUT] :

Index(['a', 'b', 'c', 'd'], dtype='object')

 

df.keys()
[OUT] :

Index(['eng', 'kor', 'math'], dtype='object')

 

df.columns
[OUT] :

Index(['eng', 'kor', 'math'], dtype='object')

 

df.values
[OUT] :

array([[10, 20, 90],
       [30, 40, 50],
       [50, 60, 20],
       [70, 80, 70]], dtype=int64)

 

df.dtypes
[OUT] :

eng     int64
kor     int64
math    int64
dtype: object

 

# df.dtypes[0]
df.dtypes['eng']
[OUT] :

dtype('int64')

 

df.info()
[OUT] :

<class 'pandas.core.frame.DataFrame'>
Index: 4 entries, a to d
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype
---  ------  --------------  -----
 0   eng     4 non-null      int64
 1   kor     4 non-null      int64
 2   math    4 non-null      int64
dtypes: int64(3)
memory usage: 288.0+ bytes

 

df


review
- df.shape[0] == len(df)
728x90
반응형
LIST