[英]Sending Pandas Dataframe with Int64 type to GCP Spanner INT64 column
[英]Force coerce pandas dataframe column to int64 type
我正在處理 TB 級的輕度嘈雜數據,這些數據被分解為約 20 GB 的數據幀。 可能每 200 萬行中有 20 行在某些列中有錯誤數據。 我想要將 pandas 數據幀列快速強制類型轉換為int
,僅將無法強制為int
的值清零(NaN)
(不要將 null 排除在整行之外)
使用pd.to_numeric(df, errors='coerce')
我已經能夠刪除字符串。 然后我的問題是使用.astype(pd.Int64Dtype())
。
這已經多次給出錯誤
"TypeError: cannot safely cast non-equivalent float64 to int64"
解決這個問題最有效的方法是什么
您是否嘗試添加downcast
參數:
df[col] = pd.to_numeric(df[col], errors='coerce', downcast='integer')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.