Advertisement
jack06215

[pandas] [tutorial] find missing columns

Sep 26th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. ix_row, ix_col = np.where(np.asanyarray(np.isnan(df)))
  2. prods = pd.DataFrame({'row_idx':ix_row,
  3.                       'col_idx':ix_col})
  4. b = [-np.inf] + np.arange(len(df.columns)).tolist() + [np.inf]
  5. l = ['Error'] + df.columns.tolist()
  6. prods['label'] = pd.cut(prods['col_idx'], bins=b, labels=l, right=False)
  7. prods = prods.drop(['col_idx'], axis=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement