I have a dataframe that has some np.inf values and I would like to isolate these rows where the np.inf appears and inspect them. However the dataframe has many columns and is not easy to examine one by one, although this could be done inside a loop.
I tried this but failed:
rows_with_inf = [df1[column][df1[column] == np.inf] for column in df1.columns if ((df1[column].isin([np.inf])).sum() !=0)]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-94-768652e951ec> in <module>
----> 1 rows_with_inf = [df1[column][df1[column] == np.inf] for column in df1.columns if ((df1[column].isin([np.inf])).sum() !=0)]
<ipython-input-94-768652e951ec> in <listcomp>(.0)
----> 1 rows_with_inf = [df1[column][df1[column] == np.inf] for column in df1.columns if ((df1[column].isin([np.inf])).sum() !=0)]
~\Anaconda3\envs\tf2\lib\site-packages\pandas\core\generic.py in __nonzero__(self)
1553 "The truth value of a {0} is ambiguous. "
1554 "Use a.empty, a.bool(), a.item(), a.any() or a.all().".format(
-> 1555 self.__class__.__name__
1556 )
1557 )
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
What would be a compact ('pythonic') way to achieve this objective?