Welcome to Working with Data and APIs in JavaScript!
This course is for aspiring developers who want to learn how to work with data in web applications. How do you retrieve, collect, and store data? The course will be taught through a series of creating three data projects.
If you haven’t watched the first part of the lesson, do that first!
This second part of the lesson looks at loading and parsing a CSV file (comma-separated values) with the web fetch() API.
🎥 PREVIOUS LESSON: https://youtu.be/tc8DU14qX6I
🎥 NEXT LESSON: https://youtu.be/5-ptp9tRApM
🎥 FULL COURSE: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6YxDKpFzf_2D84p0cyk4T7X
💻https://github.com/CodingTrain/Intro-to-Data-APIs-JS
🔗https://data.giss.nasa.gov/gistemp/
🔗https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv
🚂 Website: http://thecodingtrain.com/
💖 Patreon: https://patreon.com/codingtrain
🛒 Store: https://www.designbyhumans.com/shop/codingtrain/
📚 Books: https://www.amazon.com/shop/thecodingtrain
🎥 Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
🎥 Intro to Programming: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
🔗 p5.js: https://p5js.org
🔗 Processing: https://processing.org
📄 Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct
Original source
47 responses to “1.2 Tabular Data – Working With Data & APIs in JavaScript”
For this to work, make sure you are running a local server! I cover how to do this with node.js here: https://youtu.be/FjWbUK2HdCo?list=PLRqwX-V7Uu6Zu_uqEA6NqhLzKLACwU74X
Wish there was this quality of content for asp.net/c# microsoft related stuff
That ending clip tho! Amazing !
Hi teacher! Cheers from Brazil! Look, can you tell me how can I export the data into a json file?
Honestly was confused by the array portion and didn't expect you to go back and explain it again. Thanks so much.
this code is giving error.
<!DOCTYPE html>
<html lang="en">
<head>
<title> chart </title>
</head>
<body>
<script>
getData();
async function getData() {
const response = await fetch('RNB11017MFtest.csv');
const data = await response.text();
console.log(data);
}
</script>
</body>
</html>
error.
chart.html:12 Fetch API cannot load file://. URL scheme must be "http" or "https" for CORS request.
getData @ chart.html:12
chart.html:12 Uncaught (in promise) TypeError: Failed to fetch
at getData (chart.html:12)
at chart.html:9
hi coding train…i have a hard time to fetch the csv file…the console always show fetch api cannot load eventhough i save it in the same file directory…can you tell me how to fix this…
For handling/ removing the header Instead of using slice just start the 'for loop' at 1 and you will not add extra processes to the code.
I am just an amateur and not trying to critique your work just making an observation while learning from you many other things I have yet to put together.
Mr. Shiffman, Thanks for the great learning tools you provide.
Great tut Shiffman, you shiff us to the next level >.< (i know its a bad joke :D)
You know what? I'll come to the video and content later, Firstly I want to say you are such a nice person. It's like you are enjoying work and always happy and in a jolly mood. That makes learning fun. Thank you for making JavaScript interesting.
Also, the content is so good and the videos are so interesting.
Thankyou.
Amazing video Dan ! the editing was cool
Amazing ! Thanks Daniel.
Thanks for the best way to learn codding, can you do a livechart with chart.js, or protly.js….
Thank you for the amazing tutorials, very helpful.. My data has both numbers and text so I get undefined whenever there is a number, how do I make sure I can console log both numbers and text at the time. thank you again.
not sure if watching Bob Ross painting or a coding class
I love that you break down everything so simply and show implementation using code. You make learning this stuff a lot easier than it was for me in college. Let alone you've taught me more!
簡單明確的步驟處理csv資料,對初學者非常好👍
Seems like this example could have made use of the map function, instead of the forEach and all of the const variables. Great video as always!
Do i need some import function or something? This fetch method throws me an error "index.html:15 Fetch API cannot load file:////////test.csv. URL scheme must be "http" or "https" for CORS request." Pls help
I'd love to see your settings to vsc.
I really love this new editing style, where the references are popping out in the back as you talk 🙂 Good Job Coding Train
Everyone gets a nickle every time Dan says "beyond the scope of this video" every video
I couldn't able to use fetch(). Getting error in console on CORS. I tried to remove CORS its not worked for me. How to read local file using fetch. Could you please any one help me? Thanks in advance
You could have console.table(data)
Someone's moving towards vanilla JS
Appreciate it
I parsed it like this but its really hard to read i think.
async function getData() {
const csv = await fetch('./global_temps.csv')
const text = await csv.text()
let raw_table = text.split('n')
let raw_headers = raw_table.splice(0, 1)[0]
let parsed_data = raw_table.map(row => {
let columns = row.split(',')
let headers = raw_headers.split(',')
return headers
.map((header, index) => {
return { [header]: columns[index] }
})
.reduce((acc, item) => {
const key = Object.keys(item)[0]
const value = item[key]
acc[key] = value;
return acc
}, {})
});
parsed_data.splice(-1, 1);
}
Very good job 👍👍
Would "const table = await response.text().split('n').slice(1);" be a bad idea? Thinking that it might be nice to do splitting and slicing asynchronously if the file is huge.
cell instead of columns
Rubix Cube AI still in the works?
question: where do javascript variables live anyways? are they maybe allocated in a ram reserved for the bowser's tab, or separately? is there a limit to how much % of ram one tab can occupy, or can it take the whole ram or maybe be even stored on a hard drive if it needs be? is the transfer of the data from/to ram to/from browser slower than the transfer of the data from/to ram to/from desktop app would be, like say python ide?
also: is this csv file fetched only once, or is it being fetched repeatedly?
is that the dan that i knew who always made mistakes? I don't know when you got so professional but it looks really cool and the production and editing were at another level. sooooo kudos to you!
Amazing tutorial 👍
If you are going to make more high quality tutorials like this one, you will it 1mil subs soon
Thank you for all the great content.
Awesome👍
Can u explain how to make an A. I program? If u can, u will help me so much!
Great production in this video Daniel! Congrats to your editor. Also, great presentation by you per usual.
I'm getting this error for using the fetch function can anyone help me fix it?
Fetch API cannot load {location}. URL scheme must be "http" or "https" for CORS request.
Could you put a link to rainbow CSV in the description please?
Nice! <3
Dan, don't be afraid to say that 🐼 is a level 11 cuteness. 🙂
If anyone is interested in joining a programming community, check out https://discord.gg/bBDK2ua
Yes!!!
I was following along, but I was wondering why my temp data was different than yours? Example, 1880 , -.19 and 1881, -.10: Your set shows 1880, -.18 and 1881, -.09 ???
#dasta
(data)
But what about CORS!!