Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dataframe create new column of integer julia

I am trying to add a new column Y to a dataframe of type Float64 using another column Z of integer and an array X of type Array{Float64,1}.

When I run the command:

df[:Y] = map(z->X[z],df[:Z])

I get that that type of df[:X] is Any.

How can I change the type of df[:Y] to Float?

Example:

df = DataFrame( Z  = @data([1, 2, 3, 4, 5]) ) 
X = [1.1 2.2 3.3 4.4 5.5]
df[:Y] = map(z->X[z],df[:Z])

then typeof(df[:Y]) returns DataArrays.DataArray{Any,1}.

like image 409
grande mundo Avatar asked May 31 '26 21:05

grande mundo


1 Answers

df[:Y] = convert(DataArray{Float64,1}, map(z->X[z],df[:Z]))

Like that, or were you looking for something more?

like image 92
Alexander Morley Avatar answered Jun 04 '26 08:06

Alexander Morley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!