美文网首页
Python pandas找出空值的行

Python pandas找出空值的行

作者: 垃圾桶边的狗 | 来源:发表于2023-06-27 11:18 被阅读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

相关文章

网友评论

      本文标题:Python pandas找出空值的行

      本文链接:https://www.haomeiwen.com/subject/lhqnydtx.html