shahryarjb

shahryarjb

Undefined variable in across Explorer.DataFrame

Hello, I started the ml elixir book, the first code in this book has error for me :smiling_face_with_tear:

require Explorer.DataFrame, as: DF
iris = Explorer.Datasets.iris()
cols = ["sepal_width", "sepal_length", "petal_length", "petal_width"]

DF.mutate(iris,
  for col <- across(cols) do
    {col.name, (col - mean(col)) / variance(col)}
  end
)

Errors

** (ArgumentError) undefined variable "cols"
    (explorer 0.6.1) lib/explorer/query.ex:365: Explorer.Query.traverse/3
    (elixir 1.15.2) lib/enum.ex:1819: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (explorer 0.6.1) lib/explorer/query.ex:375: Explorer.Query.traverse/3
    (explorer 0.6.1) lib/explorer/query.ex:401: Explorer.Query.traverse_for/3
    (explorer 0.6.1) lib/explorer/query.ex:298: anonymous fn/3 in Explorer.Query.traverse/2
    (elixir 1.15.2) lib/enum.ex:1819: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (explorer 0.6.1) lib/explorer/query.ex:296: Explorer.Query.traverse/2
    (explorer 0.6.1) expanding macro: Explorer.Query.query/1

I am using LiveBook v0.10.0 and these deps:

Mix.install([
  {:axon, "~> 0.5"},
  {:nx, "~> 0.5"},
  {:explorer, "~> 0.5"},
  {:kino, "~> 0.5"}
])

It should be noted if I use the list directly it has not problem

require Explorer.DataFrame, as: DF
iris = Explorer.Datasets.iris()

DF.mutate(iris,
  for col <- across( ["sepal_width", "sepal_length", "petal_length", "petal_width"]) do
    {col.name, (col - mean(col)) / variance(col)}
  end
)

why it has this error?
Thank you in advance

Marked As Solved

codeanpeace

codeanpeace

It seems like Explorer.Query adopted a similar approach to Ecto.Query in its use of ^ for interpolation.

reference: Interpolation and Casting | Ecto.Query & Interpolation | Explorer.Query

p.s. It’s worth noting that the ^ in Ecto and Explorer is not the same as the ^ pin operator in Elixir – learn more about it here: https://stackoverflow.com/questions/73588330/why-do-ecto-queries-need-the-pin-operator

Also Liked

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir
shahryarjb

shahryarjb

I think the author should change it in the book, @seanmor5

Last Post!

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement