# Implementing a ceil function in a complete dataFrame

**URL:** <https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227>\
**Category:** New to Julia\
**Created:** [October 29, 2020, 9:05am UTC](https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227 "2020-10-29T09:05:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)\
**Post date:** [October 29, 2020, 9:05am UTC](https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227/1 "2020-10-29T09:05:40Z")

</div>

I am trying to implement the python code that looks like :  
`forecast_out =int(math.ceil(0.1*len(df)))`

in julia it looks to me:  
`forecast_out=int(ceil(0.1.*something))`

tried :  
length(df)  
df[:,:]  
don’t know how to iterate it over the whole data frame using a simple function,

also,how to shift columns in julia like for something like this :  
In python.  
df[‘label’]=df[‘forecast\_out’].shift(-forecast\_out)

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [October 29, 2020, 9:30am UTC](https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227/2 "2020-10-29T09:30:11Z")

</div>

Use:

```julia
forecast_out = ceil(Int, 0.1 * nrow(df))

```

Can you please share sample input and output so that I can clearly understand what you want to achieve?

In general to shift vectors use ShiftedArrays.jl

> don’t know how to iterate it over the whole data frame using a simple function

I am not clear what you mean by “iterate” here.

---

<div class="post-metadata">

**Author:** ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)\
**Post date:** [October 29, 2020, 9:45am UTC](https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227/3 "2020-10-29T09:45:06Z")

</div>

Input csv:  
 ![error2](https://global.discourse-cdn.com/julialang/original/3X/4/7/47d31d1a26dfdd8e193f6be01a2d8416af91b02c.jpeg)  
My code:

 ![error1](https://global.discourse-cdn.com/julialang/original/3X/1/c/1c3f2344201142e216bdd9088ff45b1aebd0013c.jpeg)  
And What I’m trying to get:  
 ![error3](https://global.discourse-cdn.com/julialang/original/3X/b/9/b9de82e3fe3864d371bf3cb061e2b16b4c8d43d9.jpeg)  
What I understood from what sentdex is saying is that he will use the data for linear regression,so what he kind of did is he shifted the data 10 days back,so he can predict for future  
His code:  
 ![error4](https://global.discourse-cdn.com/julialang/original/3X/e/6/e695bc41eb4d4961376e2b6774942d07966299ce.jpeg)

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [October 29, 2020, 10:11am UTC](https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227/4 "2020-10-29T10:11:31Z")

</div>

You have copied my code incorrectly. Here is a working example:

```julia
julia> using DataFrames, ShiftedArrays

julia> df = DataFrame(x = rand(20))
20×1 DataFrame
│ Row │ x │
│ │ Float64 │
├─────┼───────────┤
│ 1 │ 0.075843 │
│ 2 │ 0.0600812 │
│ 3 │ 0.253931 │
│ 4 │ 0.968895 │
│ 5 │ 0.711306 │
│ 6 │ 0.101996 │
│ 7 │ 0.358225 │
│ 8 │ 0.671676 │
│ 9 │ 0.775928 │
│ 10 │ 0.570634 │
│ 11 │ 0.181218 │
│ 12 │ 0.3468 │
│ 13 │ 0.255522 │
│ 14 │ 0.666059 │
│ 15 │ 0.0278363 │
│ 16 │ 0.371866 │
│ 17 │ 0.436382 │
│ 18 │ 0.0969218 │
│ 19 │ 0.551443 │
│ 20 │ 0.588202 │

julia> forecast_out = ceil(Int, 0.1 * nrow(df))
2

julia> df.y = lag(df.x, forecast_out)
20-element ShiftedArray{Float64,Missing,1,Array{Float64,1}}:
  missing
  missing
 0.075842978087997
 0.060081213070150685
 0.25393094533500715
 0.9688954060450929
 0.7113061474058524
 0.10199632559770944
 0.35822482674900225
 0.6716760713442311
 0.7759275692967518
 0.5706337841740747
 0.1812180540671371
 0.34680012499114965
 0.2555223672389133
 0.6660586930982471
 0.027836343894886317
 0.3718658603118037
 0.43638248519823497
 0.09692176577640299

julia> df.z = lead(df.x, forecast_out)
20-element ShiftedArray{Float64,Missing,1,Array{Float64,1}}:
 0.25393094533500715
 0.9688954060450929
 0.7113061474058524
 0.10199632559770944
 0.35822482674900225
 0.6716760713442311
 0.7759275692967518
 0.5706337841740747
 0.1812180540671371
 0.34680012499114965
 0.2555223672389133
 0.6660586930982471
 0.027836343894886317
 0.3718658603118037
 0.43638248519823497
 0.09692176577640299
 0.551442551906473
 0.5882020370297223
  missing
  missing

julia> df
20×3 DataFrame
│ Row │ x │ y │ z │
│ │ Float64 │ Float64? │ Float64? │
├─────┼───────────┼───────────┼───────────┤
│ 1 │ 0.075843 │ missing │ 0.253931 │
│ 2 │ 0.0600812 │ missing │ 0.968895 │
│ 3 │ 0.253931 │ 0.075843 │ 0.711306 │
│ 4 │ 0.968895 │ 0.0600812 │ 0.101996 │
│ 5 │ 0.711306 │ 0.253931 │ 0.358225 │
│ 6 │ 0.101996 │ 0.968895 │ 0.671676 │
│ 7 │ 0.358225 │ 0.711306 │ 0.775928 │
│ 8 │ 0.671676 │ 0.101996 │ 0.570634 │
│ 9 │ 0.775928 │ 0.358225 │ 0.181218 │
│ 10 │ 0.570634 │ 0.671676 │ 0.3468 │
│ 11 │ 0.181218 │ 0.775928 │ 0.255522 │
│ 12 │ 0.3468 │ 0.570634 │ 0.666059 │
│ 13 │ 0.255522 │ 0.181218 │ 0.0278363 │
│ 14 │ 0.666059 │ 0.3468 │ 0.371866 │
│ 15 │ 0.0278363 │ 0.255522 │ 0.436382 │
│ 16 │ 0.371866 │ 0.666059 │ 0.0969218 │
│ 17 │ 0.436382 │ 0.0278363 │ 0.551443 │
│ 18 │ 0.0969218 │ 0.371866 │ 0.588202 │
│ 19 │ 0.551443 │ 0.436382 │ missing │
│ 20 │ 0.588202 │ 0.0969218 │ missing │

```

---

<div class="post-metadata">

**Author:** ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)\
**Post date:** [October 29, 2020, 10:30am UTC](https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227/5 "2020-10-29T10:30:03Z")

</div>

Thank you,I reached the lag/lead function point with your direction but it still give this error of

```julia
MethodError: no method matching lag(::Array{Float64,1}, ::Int64)

Closest candidates are:

lag(!Matched::TimeSeries.TimeArray{T,N,D,A} where A<:AbstractArray{T,N} where D<:Dates.TimeType, ::Int64; padding, period) where {T, N} at C:\Users\ASHWANI\.julia\packages\TimeSeries\Kbq5K\src\apply.jl:12

1. **top-level scope** @ *[Local: 2](http://localhost:1234/edit?id=92ae8590-1993-11eb-0876-ad210e61eb52#)*

```

df.label=lag(df.adj\_close,forecast\_out)#with this one case

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [October 29, 2020, 10:33am UTC](https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227/6 "2020-10-29T10:33:52Z")

</div>

have you loaded ShiftedArrays.jl package? You loaded TimeSeries.jl package that also exports `lag`, so you need to qualify the name, like in python when you have function name clash `ShiftedArrays.lag`.

---

<div class="post-metadata">

**Author:** ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)\
**Post date:** [October 29, 2020, 10:36am UTC](https://discourse.julialang.org/t/implementing-a-ceil-function-in-a-complete-dataframe/49227/7 "2020-10-29T10:36:18Z")

</div>

Thank you,that was the error 🙂
