# How (best) to transform a huge DataFrame into wide-format

**URL:** <https://discourse.julialang.org/t/how-best-to-transform-a-huge-dataframe-into-wide-format/123415>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [December 3, 2024, 2:14pm UTC](https://discourse.julialang.org/t/how-best-to-transform-a-huge-dataframe-into-wide-format/123415 "2024-12-03T14:14:34Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [December 3, 2024, 2:14pm UTC](https://discourse.julialang.org/t/how-best-to-transform-a-huge-dataframe-into-wide-format/123415/1 "2024-12-03T14:14:34Z")

</div>

I have a DataFrame with columns like open, high, low, close, and vol for multiple tickers, e.g.

```julia
df1 = DataFrame(
date_time = repeat(["2024-12-02T14:30:00", "2024-12-02T16:00:00","2024-12-02T17:30:00", "2024-12-02T19:00:00"], outer=2),
ticker = repeat(["AAPL", "IBM"], inner=4),
open = rand(8),
high = rand(8),
low = rand(8),
close = rand(8),
vol = rand(8)*10^5
)

 Row │ date ticker open high low close vol      
     │ String String Float64 Float64 Float64 Float64 Float64  
─────┼───────────────────────────────────────────────────────────────────────────────────
   1 │ 2024-12-02T14:30:00 AAPL 0.689655 0.837242 0.636093 0.0616286 8079.08
   2 │ 2024-12-02T16:00:00 AAPL 0.70835 0.120729 0.922828 0.0278368 98275.5
   3 │ 2024-12-02T17:30:00 AAPL 0.235651 0.170414 0.854302 0.805576 26022.2
   4 │ 2024-12-02T19:00:00 AAPL 0.154155 0.977993 0.744772 0.563214 35684.5
   5 │ 2024-12-02T14:30:00 IBM 0.294663 0.70168 0.213208 0.00785374 61187.7
   6 │ 2024-12-02T16:00:00 IBM 0.740926 0.0221332 0.320625 0.102369 13345.5
   7 │ 2024-12-02T17:30:00 IBM 0.0352852 0.0763372 0.385503 0.998992 53140.9
   8 │ 2024-12-02T19:00:00 IBM 0.397259 0.606574 0.883001 0.180595 94851.4

```

Would like to transform the DataFrame (df1) into wide-format where these metrics for each timestamp are split by :ticker. In pseudo code:

```julia
df2 columns = [:date-time :AAPL_open, :AAPL_high, ... :IBM_close, :IBM_vol]

```

Which would be the best way (the real DataFrame is huge) to achieve this? Than you!

---

_[View the full topic](https://discourse.julialang.org/t/how-best-to-transform-a-huge-dataframe-into-wide-format/123415)._
