-1

Since some columns are strings, I did get numeric to exact those columns only to DF, but I received an error message when I tried to convert the negative numbers to zero

#cleaning negative minimum to equal only 0s
df2 = df._get_numeric_data()
if df2 < 0:
    then = 0
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/generic.py in __nonzero__(self)
   1535     @final
   1536     def __nonzero__(self):
-> 1537         raise ValueError(
   1538             f"The truth value of a {type(self).__name__} is ambiguous. "
   1539             "Use a.empty, a.bool(), a.item(), a.any() or a.all()."

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

  • 1
    `df2` contains _many_ values. It makes no sense to ask "Is this collection of values less than zero?", because some of them are, and some aren't. – John Gordon Nov 23 '22 at 19:37

1 Answers1

0

this method worked without using an if statment

df2 = df._get_numeric_data()

df2[df2 < 0] = 0

  • It's not recommended to use private and undocumented methods (methods that begin with underscore) in your code. If you need to identify numeric columns, refer to [this](https://stackoverflow.com/q/25039626/9987623) thread. – AlexK Nov 25 '22 at 21:55