R/tidyverseとPython/polars でやることを Julia でやるとどうなるか

Julia でやる方法は幾通りかあるが，Query を使う方法を示しておこう。ただし，Query が対応していないものについては，別法で。

https://qiita.com/nutb/items/702d1acb73043d49e8c6

```julia
using DataFrames, CSV
df = CSV.read("df.csv", DataFrame);
df_long = CSV.read("df_long.csv", DataFrame);
```

```julia
df
```

<div><div style = "float: left;"><span>3×4 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;">date</th><th style = "text-align: left;">USDJPY</th><th style = "text-align: left;">EURJPY</th><th style = "text-align: left;">SPX</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</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: left;">2023-01-01</td><td style = "text-align: right;">130.0</td><td style = "text-align: right;">140.0</td><td style = "text-align: right;">3800</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: right;">131.0</td><td style = "text-align: right;">141.0</td><td style = "text-align: right;">3900</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: right;">130.5</td><td style = "text-align: right;">143.5</td><td style = "text-align: right;">4000</td></tr></tbody></table></div>

```julia
df_long
```

<div><div style = "float: left;"><span>9×3 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;">date</th><th style = "text-align: left;">index</th><th style = "text-align: left;">value</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "String7" style = "text-align: left;">String7</th><th title = "Float64" style = "text-align: left;">Float64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">140.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">3800.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">4</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">131.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">5</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">141.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">6</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">3900.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">7</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.5</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">8</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">143.5</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">9</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">4000.0</td></tr></tbody></table></div>

```julia
using Query
```
以下で， `df |> ホニャララ |> DataFrame` のように最後が `|> DataFrame` になっているのは，Query の結果が DataFrame ではないためである。DataFrame にしなくても良い場合は，それを省くことができる。また，結果を別のデータフレームにしたい場合は `df2 = df |> ホニャララ |> DataFrame` にすればよい。ホニャララは何回も書くことができる。

```julia
# 列の選択
df |>
    @select(:date, :USDJPY) |>
    DataFrame
```

<div><div style = "float: left;"><span>3×2 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;">date</th><th style = "text-align: left;">USDJPY</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: right;">130.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: right;">131.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: right;">130.5</td></tr></tbody></table></div>

```julia
# 列の変更・追加
df |>
    @mutate(USDJPY = 2_.USDJPY) |>
    DataFrame
```

<div><div style = "float: left;"><span>3×4 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;">date</th><th style = "text-align: left;">USDJPY</th><th style = "text-align: left;">EURJPY</th><th style = "text-align: left;">SPX</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</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: left;">2023-01-01</td><td style = "text-align: right;">260.0</td><td style = "text-align: right;">140.0</td><td style = "text-align: right;">3800</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: right;">262.0</td><td style = "text-align: right;">141.0</td><td style = "text-align: right;">3900</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: right;">261.0</td><td style = "text-align: right;">143.5</td><td style = "text-align: right;">4000</td></tr></tbody></table></div>

```julia
df |>
    @mutate(EURUSD = _.EURJPY / _.USDJPY) |>
    DataFrame
```

<div><div style = "float: left;"><span>3×5 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;">date</th><th style = "text-align: left;">USDJPY</th><th style = "text-align: left;">EURJPY</th><th style = "text-align: left;">SPX</th><th style = "text-align: left;">EURUSD</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</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></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: right;">130.0</td><td style = "text-align: right;">140.0</td><td style = "text-align: right;">3800</td><td style = "text-align: right;">1.07692</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: right;">131.0</td><td style = "text-align: right;">141.0</td><td style = "text-align: right;">3900</td><td style = "text-align: right;">1.07634</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: right;">130.5</td><td style = "text-align: right;">143.5</td><td style = "text-align: right;">4000</td><td style = "text-align: right;">1.09962</td></tr></tbody></table></div>

```julia
# 複数追加する場合は @mutate を繰り返す
df |>
    @mutate(EURUSD = _.EURJPY / _.USDJPY) |>
    @mutate(foo = 100_.EURUSD) |>
    DataFrame
```

<div><div style = "float: left;"><span>3×6 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;">date</th><th style = "text-align: left;">USDJPY</th><th style = "text-align: left;">EURJPY</th><th style = "text-align: left;">SPX</th><th style = "text-align: left;">EURUSD</th><th style = "text-align: left;">foo</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</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 = "Float64" style = "text-align: left;">Float64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: right;">130.0</td><td style = "text-align: right;">140.0</td><td style = "text-align: right;">3800</td><td style = "text-align: right;">1.07692</td><td style = "text-align: right;">107.692</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: right;">131.0</td><td style = "text-align: right;">141.0</td><td style = "text-align: right;">3900</td><td style = "text-align: right;">1.07634</td><td style = "text-align: right;">107.634</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: right;">130.5</td><td style = "text-align: right;">143.5</td><td style = "text-align: right;">4000</td><td style = "text-align: right;">1.09962</td><td style = "text-align: right;">109.962</td></tr></tbody></table></div>

```julia
# 行の選択
df |>
    @filter(_.date == Date("2023-01-02")) |>
    DataFrame
```

<div><div style = "float: left;"><span>1×4 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;">date</th><th style = "text-align: left;">USDJPY</th><th style = "text-align: left;">EURJPY</th><th style = "text-align: left;">SPX</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</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: left;">2023-01-02</td><td style = "text-align: right;">131.0</td><td style = "text-align: right;">141.0</td><td style = "text-align: right;">3900</td></tr></tbody></table></div>

```julia
# ソート
df |>
    @orderby(_.date) |>
    DataFrame
```

<div><div style = "float: left;"><span>3×4 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;">date</th><th style = "text-align: left;">USDJPY</th><th style = "text-align: left;">EURJPY</th><th style = "text-align: left;">SPX</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</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: left;">2023-01-01</td><td style = "text-align: right;">130.0</td><td style = "text-align: right;">140.0</td><td style = "text-align: right;">3800</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: right;">131.0</td><td style = "text-align: right;">141.0</td><td style = "text-align: right;">3900</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: right;">130.5</td><td style = "text-align: right;">143.5</td><td style = "text-align: right;">4000</td></tr></tbody></table></div>

```julia
df |>
    @orderby_descending(_.date) |>
    DataFrame
```

<div><div style = "float: left;"><span>3×4 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;">date</th><th style = "text-align: left;">USDJPY</th><th style = "text-align: left;">EURJPY</th><th style = "text-align: left;">SPX</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</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: left;">2023-01-03</td><td style = "text-align: right;">130.5</td><td style = "text-align: right;">143.5</td><td style = "text-align: right;">4000</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: right;">131.0</td><td style = "text-align: right;">141.0</td><td style = "text-align: right;">3900</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: right;">130.0</td><td style = "text-align: right;">140.0</td><td style = "text-align: right;">3800</td></tr></tbody></table></div>

```julia
# 重複行の削除 全列を対象にする
df_long |>
    @unique() |>
    DataFrame
```

<div><div style = "float: left;"><span>9×3 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;">date</th><th style = "text-align: left;">index</th><th style = "text-align: left;">value</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "String7" style = "text-align: left;">String7</th><th title = "Float64" style = "text-align: left;">Float64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">140.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">3800.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">4</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">131.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">5</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">141.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">6</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">3900.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">7</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.5</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">8</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">143.5</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">9</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">4000.0</td></tr></tbody></table></div>

```julia
# 重複行の削除 特定の列を対象にする
df_long |>
    @unique(_.date) |>
    DataFrame
```

<div><div style = "float: left;"><span>3×3 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;">date</th><th style = "text-align: left;">index</th><th style = "text-align: left;">value</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "String7" style = "text-align: left;">String7</th><th title = "Float64" style = "text-align: left;">Float64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">131.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.5</td></tr></tbody></table></div>

```julia
# 縦長データに変換
stack(df, [:USDJPY, :EURJPY, :SPX])
```

<div><div style = "float: left;"><span>9×3 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;">date</th><th style = "text-align: left;">variable</th><th style = "text-align: left;">value</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "String" style = "text-align: left;">String</th><th title = "Float64" style = "text-align: left;">Float64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">131.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.5</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">4</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">140.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">5</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">141.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">6</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">143.5</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">7</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">3800.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">8</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">3900.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">9</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">4000.0</td></tr></tbody></table></div>

```julia
# 横長データに変換
unstack(df_long, :index, :value)
```

<div><div style = "float: left;"><span>3×4 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;">date</th><th style = "text-align: left;">USDJPY</th><th style = "text-align: left;">EURJPY</th><th style = "text-align: left;">SPX</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "Date" style = "text-align: left;">Date</th><th title = "Union{Missing, Float64}" style = "text-align: left;">Float64?</th><th title = "Union{Missing, Float64}" style = "text-align: left;">Float64?</th><th title = "Union{Missing, Float64}" style = "text-align: left;">Float64?</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">2023-01-01</td><td style = "text-align: right;">130.0</td><td style = "text-align: right;">140.0</td><td style = "text-align: right;">3800.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">2023-01-02</td><td style = "text-align: right;">131.0</td><td style = "text-align: right;">141.0</td><td style = "text-align: right;">3900.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">2023-01-03</td><td style = "text-align: right;">130.5</td><td style = "text-align: right;">143.5</td><td style = "text-align: right;">4000.0</td></tr></tbody></table></div>

```julia
# グループ化
gd = groupby(df_long, :index);
using StatsBase
combine(gd, :value => mean => :ave, :value => maximum => :max, :value => minimum => :min)
```

<div><div style = "float: left;"><span>3×4 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;">index</th><th style = "text-align: left;">ave</th><th style = "text-align: left;">max</th><th style = "text-align: left;">min</th></tr><tr class = "subheader headerLastRow"><th class = "rowNumber" style = "font-weight: bold; text-align: right;"></th><th title = "String7" style = "text-align: left;">String7</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</th><th title = "Float64" style = "text-align: left;">Float64</th></tr></thead><tbody><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">1</td><td style = "text-align: left;">USDJPY</td><td style = "text-align: right;">130.5</td><td style = "text-align: right;">131.0</td><td style = "text-align: right;">130.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">2</td><td style = "text-align: left;">EURJPY</td><td style = "text-align: right;">141.5</td><td style = "text-align: right;">143.5</td><td style = "text-align: right;">140.0</td></tr><tr><td class = "rowNumber" style = "font-weight: bold; text-align: right;">3</td><td style = "text-align: left;">SPX</td><td style = "text-align: right;">3900.0</td><td style = "text-align: right;">4000.0</td><td style = "text-align: right;">3800.0</td></tr></tbody></table></div>