我無法作出to_numeric在下面的代碼工作:大熊貓to_numeric產生ValueError異常
tt = ['123.00','10,614,163,994.00']
pd.to_numeric(tt)
我得到以下錯誤:
ValueError: Unable to parse string "10,614,163,994.00" at position 1
請幫助。
我無法作出to_numeric在下面的代碼工作:大熊貓to_numeric產生ValueError異常
tt = ['123.00','10,614,163,994.00']
pd.to_numeric(tt)
我得到以下錯誤:
ValueError: Unable to parse string "10,614,163,994.00" at position 1
請幫助。
to_numeric
不能處理,
作爲分隔符爲十萬,幾百萬,..
你應該預處理tt
通過類似tt = [n.replace(',','') for n in tt]
在tt
第二個值是不是一個數字,在數量有限的定義對於許多解析器。在嘗試進行轉換之前,只需刪除逗號。
tt = ['123.00','10,614,163,994.00']
tt = [x.replace(',','') for x in tt]
pd.to_numeric(tt)
如果在列表中有一個字符串,分裂他們的,
然後申請pd.numeric使用列表理解,因爲pd.numeric
方法的參數應該是字符串或數字的列表不是字符串單獨,
。即
tt = ['123.00','10,614,163,994.00']
([pd.to_numeric(i.split(',')) for i in tt])
輸出:
[array([ 123.]), array([ 10., 614., 163., 994.])]
Downvoter你能解釋一下嗎? – Dark
請添加一些細節/澄清你的代碼。 – Dwhitz
你應該註釋你的答案 – Krunal