Questions about saving data to a DataFrame

In this my code the Dataframe appears only one line. I’d like him to keep all the movement data.

using Printf
v₀ = 3 # velocidade inicial
g = 9.81 # aceleração da gravidade
t = range(0,1, length=100) # 1000 pontos no intervalo de 0 a 1.
y= @.v₀t - 0.5g*t^2 # fórmula para calcular a altura
i = 1 #declarando uma variável global
while y[i] >= 0
global i+=1
#println(“t(s):”,@sprintf("%.3f",t[i]), " / y(m):",@sprintf("%.3f",y[i]))
DataFrame(tempo=t[i], posição=y[i])
end
println(df)
#plot(t,y)
#plot!(xlab=“Tempo (s)”, ylab=" Altura (m)")

Best regards,

Hi @adeil,

First, it’s always a good idea to quote your code with backticks ``` like this:

using Printf
v₀ = 3 # velocidade inicial
g = 9.81 # aceleração da gravidade
t = range(0,1, length=100) # 1000 pontos no intervalo de 0 a 1.
y= @.v₀t - 0.5g*t^2 # fórmula para calcular a altura
i = 1 #declarando uma variável global
while y[i] >= 0
global i+=1
#println(“t(s):”,@sprintf("%.3f",t[i]), " / y(m):",@sprintf("%.3f",y[i]))
DataFrame(tempo=t[i], posição=y[i])
end
println(df)
#plot(t,y)
#plot!(xlab=“Tempo (s)”, ylab=" Altura (m)")

Second, I think this might be what you are trying to do?

using DataFrames
using Plots

v₀ = 3 
g = 9.81
t = range(0,1, length=100)
y = [v₀ * t - 0.5g * t^2 for t in t]

df = DataFrame(tempo=t, posição=y)

plot(t, y, xlab="Tempo (s)", ylab="Altura (m)", legend=false)

fig

If this is the case, I’d suggest working through some of the Julia intro materials at www.juliaacademy.com to flesh out your Julia toolbox a bit. That being said, keep asking questions here and have a look at this: PSA: make it easier to help you

3 Likes