bgpratt2000
Hello!
I am a BEGINNER and apologize in advance for the elementary questions.
I want to do some data transformations to a dataframe in Livebook, but currently one of the dataframe’s columns/series representing a :utc_datetime from ecto has a :string dtype, and I cannot find a simple/automated way to convert this from a :string to a :utc_datetime and then to an Explorer.Series :date.
I followed this procedure to set up the livebook:
- ran an ecto.query on my postgresql database, where my select statement returns a map with atom keys
- passed the query as an argument to Ecto.Repo.all()
- converted the map from Repo.all() to a csv file
- so far have been doing useful data transforms and visualization using Explorer and Vega_Lite in Livebook, HOWEVER: in livebook the function Explorer.DataFrame.from_csv!/1 interpreted a
:utc_datetimecolumn as a:stringseries, and I don’t know how to convert the:stringback to any useful/date-related Explorer.Series dtype.
At this exact moment I would appreciate a quick fix to this conversion struggle, but in general I hope to soon use livebook for more rigorous machine learning algorithms and data manipulations on data from my db, so any and all ways to streamline the above clunky process would be GREATLY appreciated.
Thanks! Y’all are awesome!!!
Trending in Questions
Other Trending Topics
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First Post!
dtew
The following is Claude’s LLM answer to your query - hope it helps you!
Here’s how you can handle this:
parse_datesoption to automatically parse date/datetime strings:If that doesn’t work automatically, you can manually convert the column using
mutate. Here’s how:For more control over the parsing, you can use Explorer’s datetime casting functions. Here’s a complete example:
For a more streamlined workflow from Ecto to Explorer, consider:
select_mergeto format dates in the query itselfThis would give you properly typed columns directly from your database without needing the CSV intermediate step.
The key functions to remember for datetime manipulation in Explorer are:
strptime- Parse string to datetimecast- General type conversiondt_date- Extract date from datetimeparse_datesoption infrom_csv