# DataFrames not showing value

**URL:** https://discourse.julialang.org/t/dataframes-not-showing-value/35743
**Category:** Data
**Created:** [March 9, 2020, 4:35am UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743 "2020-03-09T04:35:08Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 9, 2020, 4:35am UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/1 "2020-03-09T04:35:08Z")

</div>

```julia
d = .05
n = .01
g = .015
s = .3
k = 6
i=s
t=0:50
yn= function(t)
    ((y-k)+I*t)
using DataFrames
df = DataFrame(A = yn, B = t)
print(df)

```

When I run this, istead of giving each value of yn for each value of t, it has #11 for each value of A. Why is this, and how do I change it?

---

<div class="post-metadata">

### Author: ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)
#### Post date: [March 9, 2020, 5:20am UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/2 "2020-03-09T05:20:11Z")

</div>

Because `yn` is pointing to an anonymous function called “#11” which you then put in the column A. Are you by chance copying and pasting Matlab code? The syntax, while close, are not compatible. Here’s how the Julia code should look like.

```julia
t= 0:50

function yn(t) ## now the name of the function is yn()
   d = .05
   n = .01
   g = .015
   s = .3
   k = 6
   t*(d+n+g+s)
end 

```

You’ll see that I have defined a function called `yn` which accepts one argument called `t`. I’ve put all your local variables inside the function itself (Julia likes it when everything is inside a function). I’ve also got rid of the expression `((y-k)+I*t)` since I don’t know what `I` and `y` are and replaced it with my own expression for illustration.

You can now evaluate this function as follows: `yn(t)` where `t = 1:15` although this returns a lazy evaluator so you may need to `collect` the results… i.e. `myresults = collect(yn(t))`. Then you can assign this to a dataframe ` DataFrame(A = myresults, B = t)`.

Alternatively, given that you probably don’t have a lot of experience yet, I’d just do it more simply with a for loop

```julia
myresults = zeros(Float64, 15)
for t = 1:15 
   myresults[t] = yn(t) # evaluate the function at every time instead of a range like 1:15
end
DataFrame(A = myresults, B = 1:15)

```

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 9, 2020, 5:39am UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/3 "2020-03-09T05:39:59Z")

</div>

Now it’s repeating yn in the A column.

---

<div class="post-metadata">

### Author: ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)
#### Post date: [March 9, 2020, 7:27am UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/4 "2020-03-09T07:27:15Z")

</div>

BTW: please provide a working example, which one can improve. In your example `y` and `I` are not defined, so I can only guess what you want to do.

I see that `yn` is a function. You probably want to have in `df` the result of `yn`. So you have to **call** it when you define `df`. Maybe you intend something like that:

```julia
yn(t, y, k, I) = (y-k) .+ I .* t # definition of yn, probably you need some broadcasting in it, it returns a vector

t = 0:50
df = DataFrame(A=yn(t, 1, 6, 100:150), B=t) # now you call yn

julia> first(df, 6)
6×2 DataFrame
│ Row │ A │ B │
│ │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1 │ -5 │ 0 │
│ 2 │ 96 │ 1 │
│ 3 │ 199 │ 2 │
│ 4 │ 304 │ 3 │
│ 5 │ 411 │ 4 │
│ 6 │ 520 │ 5 │

```

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 9, 2020, 2:26pm UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/5 "2020-03-09T14:26:33Z")

</div>

I assigned a value to I, since I realize this was forgotten. Should be a MWE now

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 9, 2020, 2:28pm UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/6 "2020-03-09T14:28:23Z")

</div>

Thank’s that solved the issue. Only thing is it says yn is used, so I needed a new variable. Is there a way to remove a variable assignment in console?

---

<div class="post-metadata">

### Author: ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)
#### Post date: [March 9, 2020, 4:39pm UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/7 "2020-03-09T16:39:27Z")

</div>

you have to restart the repl (CTRL^D).

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [March 9, 2020, 5:35pm UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/8 "2020-03-09T17:35:30Z")

</div>

> [@brett\_knoss](#):
>
> yn= function(t) ((y-k)+I\*t)

you need to read a bit more regarding function declaration, mapping a function, before just putting things that **runs** in REPL and hope it does what you imagined. A quick one line way of doing what you want would be:

```julia
yn = @. (y-k)+I*t

```

though I don’t see `y`, `I` being defined…

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 9, 2020, 6:44pm UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/9 "2020-03-09T18:44:59Z")

</div>

Not sure I have REPL, or what console. On my laptop, there is no console of anykind.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [March 9, 2020, 6:52pm UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/10 "2020-03-09T18:52:05Z")

</div>

how are you using julia?

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 9, 2020, 9:25pm UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/11 "2020-03-09T21:25:04Z")

</div>

it is REPL, I had to look at it.

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 9, 2020, 9:25pm UTC](https://discourse.julialang.org/t/dataframes-not-showing-value/35743/12 "2020-03-09T21:25:49Z")

</div>

Got it. Thank you very much!
