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

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
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