Pandas dataframe에서 셀이 비어 있는지 확인하는 방법
다음 기본 구문을 사용하여 Pandas DataFrame에서 특정 셀이 비어 있는지 확인할 수 있습니다.
#check if value in first row of column 'A' is empty print (pd. isnull (df. loc [0, 'A'])) #print value in first row of column 'A' print ( df.loc [0, 'A'])
다음 예에서는 실제로 이 구문을 사용하는 방법을 보여줍니다.
예: Pandas DataFrame에서 셀이 비어 있는지 확인
다음과 같은 팬더 DataFrame이 있다고 가정합니다.
import pandas as pd import numpy as np #createDataFrame df = pd. DataFrame ({' team ': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], ' points ': [18, np.nan, 19, 14, 14, 11, 20, 28], ' assists ': [5, 7, 7, 9, np.nan, 9, 9, 4], ' rebounds ': [11, 8, 10, 6, 6, 5, 9, np.nan]}) #view DataFrame df team points assists rebounds 0 A 18.0 5.0 11.0 1 B NaN 7.0 8.0 2 C 19.0 7.0 10.0 3D 14.0 9.0 6.0 4 E 14.0 NaN 6.0 5 F 11.0 9.0 5.0 6G 20.0 9.0 9.0 7H 28.0 4.0 NaN
다음 코드를 사용하여 행 인덱스 번호 1 과 열 포인트 의 값이 0인지 확인할 수 있습니다.
#check if value in index row 1 of column 'points' is empty print (pd. isnull (df. loc [1, 'points'])) True
True 값은 “포인트” 열 중 1번 행의 값이 실제로 비어 있음을 나타냅니다.
다음 코드를 사용하여 “포인트” 열의 행 번호 1에 있는 실제 값을 인쇄할 수도 있습니다.
#print value in index row 1 of column 'points' print ( df.loc [1, 'points']) Nope
출력은 “points” 열의 행 번호 1에 있는 값이 nan 이며 이는 빈 셀과 동일하다는 것을 알려줍니다.
추가 리소스
다음 튜토리얼에서는 Pandas에서 다른 일반적인 작업을 수행하는 방법을 설명합니다.
Pandas에서 특정 셀의 값을 설정하는 방법
팬더에서 셀의 가치를 얻는 방법
Pandas에서 NaN 값을 0으로 바꾸는 방법