5
1

eyecatch-polars-1-960x504.jpg

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"])

無事読み込めました。

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1