alphydan

alphydan

Hello,

I’m an elixir beginner, exploring livebook. I’m running a local notebook on a linux machine. Initially I tried to import a CSV file with Explorer like so:

alias Explorer.{DataFrame, Series}
path_to_csv = "./some_file.csv"
DataFrame.from_csv!(path_to_csv)

However, I am seeing the following error:

** (RuntimeError) from_csv failed: {:polars, "Could not parse `Fee Amount` 
    as dtype Int64 at column 16.\nThe current offset in the file is 249 bytes.\n\n
    Consider specifying the correct dtype, increasing\n
    the number of records used to infer the schema,\n
    enabling the `ignore_errors` flag, or adding\n`Fee Amount` to the `null_values` list."}
    (explorer 0.5.5) lib/explorer/data_frame.ex:438: Explorer.DataFrame.from_csv!/2

To check if the problem was indeed with the data in the column Fee Amount, I filled the column with integers. But I get the same error. What can I try to better diagnose this problem?

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @alphydan welcome! Are you able to provide a sample of that CSV file?

BradS2S

BradS2S

You can use :dtype to explicitly set the data type for a column instead of letting it try to infer it.

al2o3cr

al2o3cr

One small thing that jumps out:

Could not parse Fee Amount as dtype Int64 at column 16.
The current offset in the file is 249 bytes.

This sounds like it’s on at least the second line of the file, and so should be data

That’s a reference to the with_null_values setting in polars_io::csv::CsvReader, which is intended to parse values like "n/a" to null.

The message suggests that the reader found the literal string “Fee Amount” where it expected data.

:thinking: what was a header-shaped value like “Fee Amount” doing on the second line of a CSV?

alphydan

alphydan OP

@BradS2S @benwilson512 @al2o3cr Thank you for all your suggestions. “Fee Amount” was not on the second line, but on the header (first row).

A potential problem with the header led me to try changing all headers to the format something_or_the_other instead of Something Or \n the Other.

I found that it failed when I had a return character inside the header. The CSV gets imported correctly now. Thank you for the prompt replies.

LostKobrakai

LostKobrakai

Were these quoted? If no, then that’s indeed invalid. If they were, then this sounds like a but in the csv parser.

alphydan

alphydan OP

Ok, here’s an example to further diagnose the problem:

Running $ cat -v example_failing.csv in the terminal shows:

"Timestamp$
(ISO)",Animal Type,Animal Color,"Friends of$
Given Animal","Another$
Timestamp$
(ISO)",Feedstock,"Favorite food$
for Animal",Feed Amount,Feed Frequency^M$
2023,Tiger,Yellow,Lion,2023-03-14,3,meat,32.2,weekly^M$
2023,Tiger,Yellow,Lion,2023-03-14,3,meat,32.2,weekly

(Where $ corresponds to \n or Unix line endings). Trying to import it in livebook:

path_to_csv = "./example_failing.csv"
IO.puts(path_to_csv)
DataFrame.from_csv!(path_to_csv)

leads to this error:

** (RuntimeError) from_csv failed: {:polars, "Could not parse `(ISO)\"` as dtype Int64 at column 1.\n
The current offset in the file is 11 bytes.\n\n

Consider specifying the correct dtype, increasing\n
the number of records used to infer the schema,\n
enabling the `ignore_errors` flag, or adding
\n`(ISO)\"` to the `null_values` list."}
    (explorer 0.5.5) lib/explorer/data_frame.ex:438: Explorer.DataFrame.from_csv!/2
BradS2S

BradS2S

Remove all the new line characters from the column headers.

LostKobrakai

LostKobrakai

That sounds like a bug / missing implementation in the parser of polars then. LF or CRLF are supposed to be allowed in quoted fields based on RFC 4180.

alphydan

alphydan OP

Removing all return characters leads to an import without errors.

"Timestamp (ISO)",Animal Type,Animal Color,"Friends of Given Animal","Another Timestamp (ISO)",Feedstock,"Favorite food for Animal",Feed Amount,Feed Frequency^M
2023,Tiger,Yellow,Lion,2023-03-14,3,meat,32.2,weekly^M
2023,Tiger,Yellow,Lion,2023-03-14,3,meat,32.2,weekly

is imported correctly. Does that mean that return characters are not allowed in headers, even with quotes?

return characters outside the header seem to be imported correctly. for example, if I have an element of the csv be Tiger and \nBeasts, but no returns in the header I can see:

  Polars[2 x 9]
  Timestamp (ISO) integer [2023, 2023]
  Animal Type string ["Tiger and \nBeasts", "Tiger"]
  Animal Color string ["Yellow", "Yellow"]
  Friends of Given Animal string ["Lion", "Lion"]
  Another Timestamp (ISO) string ["2023-03-14", "2023-03-14"]
  Feedstock integer [3, 3]
  Favorite food for Animal string ["meat", "meat"]
  Feed Amount float [32.2, 32.2]
  Feed Frequency string ["weekly", "weekly"]
``
BradS2S

BradS2S

Yes you want it on a single line. That parsing error means they don’t expect labels to be on more than one line

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews