nada
[Python] Series 행 반환 :: Series.head( ) | tail( ) | sample( ) 본문
Python/Pandas
[Python] Series 행 반환 :: Series.head( ) | tail( ) | sample( )
ds-nada 2023. 8. 10. 01:04Series 행 반환
Reference
Pandas In Actionimport pandas as pd
values = range(0,500,5)
nums = pd.Series(data = values)
nums
0 0
1 5
2 10
3 15
4 20
...
95 475
96 480
97 485
98 490
99 495
Length: 100, dtype: int64
1. Series 상위 행 반환 :: Series.head( )
Series.head(
n = 5
)
- 처음 n개의 행을 반환
- Option
- n : 선택할 행 수
nums.head() # nums의 상위 5개의 행 반환
0 0
1 5
2 10
3 15
4 20
dtype: int64
2. Series 하위 행 확인 :: Series.tail( )
Series.tail(
n = 5
)
- 마지막 n개의 행을 반환
- Option
- n : 선택할 행 수
nums.tail() # nums의 하위 5개의 행 반환
95 475
96 480
97 485
98 490
99 495
dtype: int64
3. Series 임의 값 추출 :: Series.sample( )
Series.sample(
n = None,
random_state = None,
axis = None # 0 or 'index' | 1 or 'columns'
)
- 객체의 축에서 임의의 항목 샘플을 반환
- Option
- n : 반환할 축의 항목 수
- random_state : 난수 생성기의 시드 값
- axis : 반환할 축
nums.sample(3) # nums 중 임의의 3개의 행
14 70
35 175
84 420
dtype: int64
'Python > Pandas' 카테고리의 다른 글
[Python] Series 값의 유형 :: Series.dtype (0) | 2023.08.15 |
---|---|
[Python] Series 인덱스 & 값 확인 :: Series.index | Series.values (0) | 2023.08.14 |
[Python] JSON 파일 불러오기 :: pd.read_json( ) (0) | 2023.08.09 |
[Python] Excel 파일 불러오기 :: pd.read_excel() (0) | 2023.08.07 |
[Python] CSV 파일 불러오기 :: pd.read_csv( ) (0) | 2023.08.07 |