5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「関数型でデータサイエンス#2」で躓いた箇所

Last updated at Posted at 2019-08-14

7/30 fukuoka.ex#27:Elixir/Phoenixもくもく会に参加しました。

私は@piacerex さんの関数型でデータサイエンスを#1から実装していきました。
順調に進んでいたのですが、関数型でデータサイエンス#2の正規化でエラーが出てしまいました。もくもく会の中では解決できなかったので、改めて調べてみました。

エラー内容

error.png
min = result |> Enum.map( &( &1[ "ApplicantIncome" ] ) ) |> Enum.min |> String.to_integer

Webページにアクセスしようとすると、画像のようなエラーになります。
ハイライトされている部分がエラーだと分かりますが、エラーの原因が分かりません。

エラーの調査

まずはパイプラインを1つづつ試しながらエラー箇所を絞り込みました。

:erlang.binary_to_integer/1
>Called with 1 arguments
 1. nil

エラー箇所を特定して見ると|> String.to_integerに nil が渡っているのが原因のようです。

min = result |> Enum.map( &( &1[ "ApplicantIncome" ] ) ) |> Enum.min 

を表示してみると確かに何も表示されていませんでした。
Enum.min以前に、Enum.mapの値も取得できていませんでした。

解決

こうなると取得元のCSVファイルが怪しそうです。
CSVの列がどう格納されているのかを表示してみました。

columns.png

各列に「 ApplicantIncome」のような空白が含まれています。
CSVファイルは次のようになっています。どうやらカンマの後ろの空白も列名に含まれるようです。

ID, Gender, Profession, ApplicantIncome, CoapplicantIncome, LoanAmount, LoanStartDatetime

CSVファイルの空白を詰めてみました。
result.png

無事に表示されました。

5
0
2

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?