Julia でデータフレームをフィルターすると

以下を参照して，Julia ならどうなるかやってみた。
https://qiita.com/yossy_stu/items/9c943c2f01b5a941666d

## 作業環境

|種類|バージョン|
:-----|:-----
Mac mini | 
チップ | Apple M1
メモリ | 8 GB
macOS Ventura | 13.1
Python | 3.11.0
pandas | 1.5.1
Julia | 1.8.5
Query | 1.0.0
jupyterlab | 3.4.1


結論からいえば，直接指定 `df[df.foo > x, :]` が一番速いが，Python に比べると 10 倍ほど遅い。

```julia
using DataFrames, CSV
@time df = CSV.read("../SN_d_tot_V2.0.csv", DataFrame,
    delim=";",
    header=["year", "month", "day", "date_frac", "num", "std", "obs spot", "certanty"]
    );

```

      3.139465 seconds (1.55 M allocations: 73.513 MiB, 0.55% gc time, 99.25% compilation time: 85% of which was recompilation)

読み込みは Python の場合 0.030 〜 0.035 秒ほど。Julia だと約 2 倍速。

使用する変数（列）だけ読み込むようにしても，特段早くなるわけでもない。

```julia
@time df2 = CSV.read("../SN_d_tot_V2.0.csv", DataFrame,
    delim=";",
    header=["year", "month", "day", "date_frac", "num", "std", "obs spot", "certanty"],
    select=["num"]
    );
```

      0.034364 seconds (46.22 k allocations: 3.047 MiB, 52.56% compilation time)

```julia
using Query
```

```julia
# 行の選択
@time df |>
    @filter(_.date_frac >= 2000) |>
    @take(3) |>
    DataFrame
```

      0.422586 seconds (2.46 M allocations: 128.434 MiB, 3.40% gc time, 99.25% compilation time)

<div><div style = "float: left;"><span>3×8 DataFrame</span></div><div style = "clear: both;"></div></div><div class = "data-frame" style = "overflow-x: scroll;"><table class = "data-frame" style = "margin-bottom: 6px;"><thead><tr class = "header"><th class = "rowNumber" style = "font-weight: bold; text-align: right;">Row</th><th style = "text-align: left;">year</th><th style = "text-align: left;">month</th><th style = "text-align: left;">day</th><th style = "text-align: left;">date_frac</th><th style = "text-align: left;">num</th><th style = "text-align: left;">std</th><th style = "text-align: left;">obs spot</th><th style = "text-align: left;">certanty</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Int64" style = "text-align: left;">Int64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: right;">2000</td><td style = "text-align: right;">1</td><td style = "text-align: right;">1</td><td style = "text-align: right;">2000.0</td><td style = "text-align: right;">71</td><td style = "text-align: right;">3.8</td><td style = "text-align: right;">14</td><td style = "text-align: right;">1</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: right;">2000</td><td style = "text-align: right;">1</td><td style = "text-align: right;">2</td><td style = "text-align: right;">2000.0</td><td style = "text-align: right;">75</td><td style = "text-align: right;">4.1</td><td style = "text-align: right;">10</td><td style = "text-align: right;">1</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: right;">2000</td><td style = "text-align: right;">1</td><td style = "text-align: right;">3</td><td style = "text-align: right;">2000.01</td><td style = "text-align: right;">80</td><td style = "text-align: right;">3.9</td><td style = "text-align: right;">13</td><td style = "text-align: right;">1</td></tr></tbody></table></div>

Python の `df_dSN.query('date_frac >= 2000').head(3)` だと 0.003 秒ほどなのに比べるととても遅い。

```julia
@time df[df.date_frac .>= 2000, :] |> (x -> first(x, 3))
```

      0.170744 seconds (474.33 k allocations: 23.493 MiB, 99.75% compilation time: 65% of which was recompilation)

<div><div style = "float: left;"><span>3×8 DataFrame</span></div><div style = "clear: both;"></div></div><div class = "data-frame" style = "overflow-x: scroll;"><table class = "data-frame" style = "margin-bottom: 6px;"><thead><tr class = "header"><th class = "rowNumber" style = "font-weight: bold; text-align: right;">Row</th><th style = "text-align: left;">year</th><th style = "text-align: left;">month</th><th style = "text-align: left;">day</th><th style = "text-align: left;">date_frac</th><th style = "text-align: left;">num</th><th style = "text-align: left;">std</th><th style = "text-align: left;">obs spot</th><th style = "text-align: left;">certanty</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Int64" style = "text-align: left;">Int64</th><th title = "Int64" style = "text-align: left;">Int64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: right;">2000</td><td style = "text-align: right;">1</td><td style = "text-align: right;">1</td><td style = "text-align: right;">2000.0</td><td style = "text-align: right;">71</td><td style = "text-align: right;">3.8</td><td style = "text-align: right;">14</td><td style = "text-align: right;">1</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: right;">2000</td><td style = "text-align: right;">1</td><td style = "text-align: right;">2</td><td style = "text-align: right;">2000.0</td><td style = "text-align: right;">75</td><td style = "text-align: right;">4.1</td><td style = "text-align: right;">10</td><td style = "text-align: right;">1</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: right;">2000</td><td style = "text-align: right;">1</td><td style = "text-align: right;">3</td><td style = "text-align: right;">2000.01</td><td style = "text-align: right;">80</td><td style = "text-align: right;">3.9</td><td style = "text-align: right;">13</td><td style = "text-align: right;">1</td></tr></tbody></table></div>

Python の `df_dSN[df_dSN['date_frac'] >= 2000].head(3)` だと 0.002 秒ほどなのに比べるととても遅い。

```julia
@time filter(:date_frac => x -> x >= 2000, df) |> (x -> first(x, 3))
size(df)
```

      0.168857 seconds (1.53 M allocations: 82.448 MiB, 9.10% gc time, 99.77% compilation time)

    (74875, 8)

```julia
df2 = copy(df)
@time filter!(:date_frac => x -> x >= 2000, df2) |> (x -> first(x, 3))
size(df2)
```

      0.159689 seconds (799.11 k allocations: 41.806 MiB, 4.68% gc time, 99.54% compilation time)

    (8401, 8)

インプレースで操作してもほとんど速度の変化はない。