我想知道如何从包含NaN的数据帧中删除这些行。我制作了这个有效的代码,但必须有更简单的方法。也许我可以为此实现一个循环?
X=pd.DataFrame()
X['annual_inc']=annual_inc
X['delinq_2yrs']=delinq_2yrs
X['dti']=dti
X['emp_length']=emp_length
X['loan_amnt']=loan_amnt
X['installment']=installment
X['int_rate']=int_rate
X['total_acc']=total_acc
X['open_acc']=open_acc
X['pub_rec']=pub_rec
X['acc_now_delinq']=acc_now_delinq
X['loan_stat']=loan_stat
X=X[np.isfinite(X['annual_inc'])]
X=X[np.isfinite(X['delinq_2yrs'])]
X=X[np.isfinite(X['dti'])]
X=X[np.isfinite(X['emp_length'])]
X=X[np.isfinite(X['loan_amnt'])]
X=X[np.isfinite(X['installment'])]
X=X[np.isfinite(X['int_rate'])]
X=X[np.isfinite(X['total_acc'])]
X=X[np.isfinite(X['open_acc'])]
X=X[np.isfinite(X['pub_rec'])]
X=X[np.isfinite(X['acc_now_delinq'])]
X=X[np.isfinite(X['loan_stat'])]