Polarsは並列処理エンジン、効率的なアルゴリズム、SIMD(Single Instruction, Multiple Data)によるベクトル化の使用により、Pandasよりも30倍ほど早く処理できると言われているサードパーティのライブラリです。使い勝手はPandasを意識してつくられています。
課題
例えば、こちらのkaggleのデータセットを読み込もうとすると次のエラーが出ます。
[in]
import polars as pl
df = pl.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/train.csv')
[out]
ComputeError: could not parse `NA` as dtype `i64` at column 'MasVnrArea' (column number 27)
'MasVnrArea'という名前の列はint64で読み込もうとしているが、NA
は数値にできないと言われています。
'NA'
というデータがnullとして扱われていないため、このようなエラーが出ます。
解決策
Polarsでは'null'
が欠損値として扱われるので、オプションでnull_values
をつけて、欠損値を指定します。
df = pl.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/train.csv', null_values=["NA"])