From the course: D3.js Essential Training for Data Scientists

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Parsing a TXT file

Parsing a TXT file - D3.js Tutorial

From the course: D3.js Essential Training for Data Scientists

Start my 1-month free trial

Parsing a TXT file

- [Instructor] In this section, we're going to look at importing data from a text file. If you can avoid using a text file, do. It's often more robust to use another format, and it is certainly simpler. Previously, we imported a text file, but actually it was a pipe-delimited file in disguise. And this time, we're going to import a proper text file. So, I'm going to be using this file, which is called test.txt, and if you don't have access to it, you can just copy what's on the screen now. D3 imports text files as strings. The strings contain the tabs and new-line commands that create the structure we see in the text. But D3 doesn't automatically break it down into rows. It pulls it in as one long string. In this section, I'm going to assume that you do in fact want rows. I'm going to show you one way of parsing a text file. To load it, we use d3.text, just as we did before. And then, in there, we pop the URL, which is test.txt, and we know that we can use get but we can't use row…

Contents