question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Read csv with custom delimiter

See original GitHub issue

I’m trying to read a csv file with ‘#’ as delimiter I haven’t found anyway to specify this in the read function.

Is this possible?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
SheetJSDevcommented, May 1, 2018

The DSV reader follows Excel rules. For a delimiter other than the standard comma or tab or semicolon, your file should start with sep= followed by the separator character. You can verify this manually in Excel.

This file will have 2 cells:

1#2#3
4#5#6

This file will have 6 cells:

sep=#
1#2#3
4#5#6

There currently is no override but it is fairly straightforward to add one and we would accept a PR if you are interested. To be consistent with the writer, the option should be called FS. https://github.com/SheetJS/js-xlsx/blob/master/bits/40_harb.js#L770 is where the delimiter is determined, and the check should apply after the sep override:

		if(str.slice(0,4) == "sep=" && str.charCodeAt(5) == 10) { sep = str.charAt(4); str = str.slice(6); }
+		else if(o.FS) sep = o.FS;
		else sep = guess_sep(str.slice(0,1024));

0reactions
garrettluucommented, Jun 18, 2020

Upon a deeper look at this issue i can see that the code is checking if there is the char code for a new line present at position 5, this is looking for the char code 10 - whereas my file has a char code of 13 for the new line

@louisjacksonrees this bug was fixed in this PR: #2004

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to read a CSV file to a Dataframe with custom delimiter in ...
This method uses comma ', ' as a default delimiter but we can also use a custom delimiter or a regular expression as...
Read more >
Read csv file to Dataframe with custom delimiter in Python
In this article we will discuss how to read a CSV file with different type of delimiters to a Dataframe. Python's Pandas library...
Read more >
Pandas read_csv() With Custom Delimiters - AskPython
Let's now learn how to use a custom delimiter with the read_csv() function. We'll show you how different commonly used delimiters can be...
Read more >
How to open CSV files with the correct delimiter/separator
Open your CSV using a text editor. · Press Enter/Return to create a new line at the very top, and add sep=; if...
Read more >
Understanding Delimiters in Pandas read_csv() Function
Reading CSV Files using Pandas. To read these CSV files or read_csv delimiter, we use a function of the Pandas library called read_csv()....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found