# Interpolate DataFrame columns

**URL:** <https://discourse.julialang.org/t/interpolate-dataframe-columns/60632>\
**Category:** New to Julia\
**Tags:** dataframes, interpolations\
**Created:** [May 6, 2021, 9:13am UTC](https://discourse.julialang.org/t/interpolate-dataframe-columns/60632 "2021-05-06T09:13:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alessio](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@alessio](https://discourse.julialang.org/u/alessio)\
**Post date:** [May 6, 2021, 9:13am UTC](https://discourse.julialang.org/t/interpolate-dataframe-columns/60632/1 "2021-05-06T09:13:12Z")

</div>

I have a DataFrame sorted on one column (X):

```julia
df = sort(DataFrame(Y = rand(4), X = rand(4)), [:X])
4×2 DataFrame
 Row │ Y X
     │ Float64 Float64
─────┼────────────────────
   1 │ 0.211423 0.491155
   2 │ 0.839856 0.506252
   3 │ 0.344844 0.731106
   4 │ 0.196441 0.963763

```

I would like to create a new DataFrame whose X points are evenly distributed across [0,1] that interpolate Y.

Something like that:

```julia
4×2 DataFrame
 Row │ Y X
       │ Float64 Float64
───────┼────────────────────
   1 │ ... 0
   2 │ ... 0.01
....................................
   N-1 │ ... 0.99
   N │ ... 1

```

I’ve tried using interpolation and extrapolations without success.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 6, 2021, 11:10am UTC](https://discourse.julialang.org/t/interpolate-dataframe-columns/60632/2 "2021-05-06T11:10:42Z")

</div>

I don’t understand the question - are you saying you have some observations `Y` at some points `X` and want to interpolate the value of `Y` on some points `X*` that aren’t observed?

If so, that doesn’t seem to have anything to do with DataFrames, and you should probably look at [Home · Interpolations.jl](https://juliamath.github.io/Interpolations.jl/latest/) (and the other packages mentioned on the landing page of the docs) to find an appropriate interpolation scheme for your data.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 6, 2021, 11:12am UTC](https://discourse.julialang.org/t/interpolate-dataframe-columns/60632/3 "2021-05-06T11:12:23Z")

</div>

For example:

```julia
using DataFrames, Interpolations

df = sort(DataFrame(Y = rand(4), X = rand(4)), [:X])

intlin = LinearInterpolation(df[:,:X], df[:,:Y], extrapolation_bc=Line());
x = 0:0.02:1;
y = intlin(x)

df_int = DataFrame(Xint = x, Yint = y)

```

![DataFrame_Interpolations](https://global.discourse-cdn.com/julialang/original/3X/0/e/0e8a23f1773f455598092b87540a043e5382014f.png)

---

<div class="post-metadata">

**Author:** ![alessio](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@alessio](https://discourse.julialang.org/u/alessio)\
**Post date:** [May 6, 2021, 11:12am UTC](https://discourse.julialang.org/t/interpolate-dataframe-columns/60632/4 "2021-05-06T11:12:30Z")

</div>

Yes, one of the issues I’m having I guess is converting the two DataFrame columns to the format required by interpolate
