Python pandas找出空值的行

2023-06-27  本文已影响0人  垃圾桶边的狗
import pandas as pd
import numpy as np
     
n = np.arange(20, dtype=float).reshape(5,4)

n[2,3] = np.nan
n[4,1] = np.nan
index = ['index1', 'index2', 'index3', 'index4', 'index5']
columns = ['column1', 'column2', 'column3', 'column4']
frame3 = pd.DataFrame(data=n, index=index, columns=columns)
display(frame3)

# 找到空值对应的行与列
print(frame3[frame3.isnull().T.any()])

image.png
上一篇 下一篇

猜你喜欢

热点阅读