Reputation: 1894
I have this 'position1' df (and I am trying to sum my total portfolio's worth):
total Last_P
BNB 0.77063139 18.33230000
BTC 1.4e-07 5235.88000000
EOS 0.0073 5.82520000
ETH 1.31e-06 178.51000000
USDT 80.13510905 NaN
XRP 300 0.35374000
the above is an object and after using:
position1.info()
position1 = pd.to_numeric(position1, downcast='float')
#position1 = pd.to_numeric(position1, errors='coerce')#tried this
#position1.apply(lambda x: pd.to_numeric(x), axis=0)#tried this
print(position1)
position1.info()
I am getting an error:
TypeError: arg must be a list, tuple, 1-d array, or Series
Please advice how to solve this
Upvotes: 1
Views: 48
Reputation: 531
pd.to_numeric
only works on a list, tuple, 1-d array, or Series as stated in the error that you mention. In order to apply it to a DataFrame, you need to use the apply method:
position1.apply(pd.to_numeric)
Note that, as most functions in pandas, this operation does not happen "in place" by default
Upvotes: 2