imed-code
Explorer DataFrame.new like Pandas (rows and columns)
Dear all,
I’m trying to use the new Library Explorer DataFrame as we have for Pandas (python) loading rows and columns arrays.
I have an output parsing HTML table and creating an array of columns and rows.
def transform_request(body) do
columns =
body
|> Floki.parse_document!()
|> Floki.find("td.dxgvHeader_DevEx")
|> Floki.find("tr")
|> Enum.map(fn {"tr", [],
[
{"td", [{"style", "font-size:10pt;font-weight:normal;"}], [topic]},
{"td", [{"style", "width:1px;text-align:right;"}], [_topic_span]}
]} ->
String.downcase(topic)
end)
rows =
body
|> Floki.parse_document!()
|> Floki.find("tr.dxgvDataRow_DevEx")
|> Floki.find("td")
|> Enum.map(&parse_row/1)
**DF.new(rows, columns)**
end
defp parse_row(
{"td", [{"class", "dxgv"}, {"align", "right"}, {"style", "font-family:Arial;"}], [topic]}
) do
#%{data: String.trim(topic)}
String.trim(topic)
end
defp parse_row(_), do: ""
How can I load this Explorer DataFrame using columns and rows as an input? By the way, same code in pandas works very well e.g. pd.DataFrame(rows[1:], columns=rows[0])
Marked As Solved
NduatiK
Explorer’s accepts a list of maps in it’s DataFrame.new function.
columns = ["patient", "age", "gender"]
rows = [
["Sergio", 40, "M"],
["Maria", 12, "F"],
["João", 21, "M"],
["Mirela", 52, "F"]
]
rows
|> Enum.map(fn row ->
columns
|> Enum.zip(row)
|> Enum.into(%{})
end)
|> Explorer.DataFrame.new()
#Explorer.DataFrame<
Polars[4 x 3]
age integer [40, 12, 21, 52]
gender string ["M", "F", "M", "F"]
patient string ["Sergio", "Maria", "João", "Mirela"]
>
By the way, it sounds like you will be pushing this into a DB and serving it over an API, unless you are using Explorer for other data manipulation, you might want to skip using DataFrames.
3
Last Post!
imed-code
Popular in Questions
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
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
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
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
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
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
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
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
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
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









