How to change separator for CSV files? (Date separation issue)

2,374 views
Skip to first unread message

David Valencia

unread,
Apr 18, 2012, 3:06:58 PM4/18/12
to dygraph...@googlegroups.com
Hello !

We have an issue. We wish to change the data separator from a comma to a space, but we cannot manage
to correctly separate the date from the data.

Our original data looks like this:

Fecha,X1,X2,Y1,Y2
2012/04/12 11:51:07,-0.29938657795953244,0.8832056642353587,1.500289925840022,2.695394756920072
2012/04/12 11:51:08,0.08087405011139256,1.0583819086275825,1.881771294289987,2.585528122806482
2012/04/12 11:51:09,-0.16174810022278513,0.695516830957976,1.7102572710348827,2.801599169896542
2012/04/12 11:51:10,-0.21118808557390056,0.6210516678365429,1.9440290536210212,2.2592852565080723
2012/04/12 11:51:11,-0.2706991790520951,0.5816827906125065,1.587267677846614,2.7600939970091862

And we wish it had spaces instead of commas, like this:

Fecha X1 X2 Y1 Y2
2012/04/12 11:51:07 -0.29938657795953244 0.8832056642353587 1.500289925840022 2.695394756920072
2012/04/12 11:51:08 0.08087405011139256 1.0583819086275825 1.881771294289987 2.585528122806482
2012/04/12 11:51:09 -0.16174810022278513 0.695516830957976 1.7102572710348827 2.801599169896542
2012/04/12 11:51:10 -0.21118808557390056 0.6210516678365429 1.9440290536210212 2.2592852565080723
2012/04/12 11:51:11 -0.2706991790520951 0.5816827906125065 1.587267677846614 2.7600939970091862
2012/04/12 11:51:12 -0.05951109347819453 0.8062990203558458 1.9534897915585803 2.7140110477004304
2012/04/12 11:51:13 0.02227851191747795 1.0522782067323833 1.8021179845576343 2.4506363109225746

The problem is that (as expected) the Date doesn't get correctly parsed (interpreted by Dygraphs)

Why do we want this? Apart from being displayed by Dygraphs, we want them to be useful for mathematic analysis, and their program works better with space-separated CSV's.

Robert Konigsberg

unread,
Apr 18, 2012, 3:33:42 PM4/18/12
to ing....@gmail.com, dygraph...@googlegroups.com
I think you're just going to have to parse the file yourself into an array format.
--
Robert Konigsberg | Google NY | http://go/monarch


Message has been deleted

Dan Vanderkam

unread,
Apr 18, 2012, 3:42:39 PM4/18/12
to ing....@gmail.com, dygraph...@googlegroups.com
There is a "delimiter" option which you will find useful. Set it to
space and you'll be good to go.

http://dygraphs.com/options.html#delimiter

- Dan

On Wed, Apr 18, 2012 at 3:39 PM, David Valencia <ing....@gmail.com> wrote:
> Does that mean that Dygraphs supports only comma-separated CSVs ?

Robert Konigsberg

unread,
Apr 18, 2012, 3:43:01 PM4/18/12
to ing....@gmail.com, dygraph...@googlegroups.com
It would support space-separated CSVs if you didn't have a space in your date. By doing that you're effectively splitting the date into two fields, and then you would only have x-values of dates without times.

See http://dygraphs.com/data.html for more details.

On Wed, Apr 18, 2012 at 3:39 PM, David Valencia <ing....@gmail.com> wrote:
Does that mean that Dygraphs supports only comma-separated CSVs ?

El miércoles, 18 de abril de 2012 14:33:42 UTC-5, konigsberg escribió:

Robert Konigsberg

unread,
Apr 18, 2012, 3:43:30 PM4/18/12
to dan...@gmail.com, ing....@gmail.com, dygraph...@googlegroups.com
My assertion is that he won't be good to go -- his date has spaces in it, and his date field will be split in two.

Dan Vanderkam

unread,
Apr 18, 2012, 3:45:39 PM4/18/12
to konig...@google.com, ing....@gmail.com, dygraph...@googlegroups.com
Ah, true! I suspect your math program will have a similar issue with this.

One option is to switch to a format like "2012-04-18T15:45:01", which
doesn't have a space. Note that this will have the (surprising) side
effect of changing your dates to be UTC, though.

- dan

David Valencia

unread,
Apr 18, 2012, 3:46:39 PM4/18/12
to dygraph...@googlegroups.com
Precisely, it'd split the date into "date" and "time" and that shouldn't work.

Is there a DateFormat that "pastes" date and time together to avoid the separating space?

El miércoles, 18 de abril de 2012 14:43:01 UTC-5, konigsberg escribió:
It would support space-separated CSVs if you didn't have a space in your date. By doing that you're effectively splitting the date into two fields, and then you would only have x-values of dates without times.

See http://dygraphs.com/data.html for more details.

On Wed, Apr 18, 2012 at 3:39 PM, David Valencia <> wrote:
Does that mean that Dygraphs supports only comma-separated CSVs ?

El miércoles, 18 de abril de 2012 14:33:42 UTC-5, konigsberg escribió:
I think you're just going to have to parse the file yourself into an array format.

Robert Konigsberg

unread,
Apr 18, 2012, 3:50:12 PM4/18/12
to ing....@gmail.com, dygraph...@googlegroups.com
There is not, but honestly, it's not that hard to do the parsing yourself. Sure, it's super convenient to provide a URL-as-string when creating the dygraph (I do love it, myself), but if you needed to do it all yourself, it's surprisingly not that much code. I'd love for Dygraphs to support alternative parsing of URL-based data, but I question its value, again, given the code you need to write is rather small. I'll write a blog post demonstrating this very issue (fetching from a URL, and parsing into a preferred format.)

Robert Konigsberg

unread,
Apr 30, 2012, 7:07:24 PM4/30/12
to ing....@gmail.com, dygraph...@googlegroups.com
I finally wrote the blog post that will help you: http://blog.dygraphs.com/2012/04/how-to-download-and-parse-data-for.html
Reply all
Reply to author
Forward
0 new messages