Repository navigation
Datacleaning
To show that I am able to clean data, I'm going to clean a row of the CMD survey data. Specifically the row with student hobbys.
I put the row I'm going to clean as a string in my Javascript file.
Raw data
Gamen, uitgaan handbal Tekenen; ukelele spelen; schilderen; koken; bakken; haken; films; video's maken; fotografie Sporten; muziek luisteren; series kijken; films kijken; met vrienden uithangen Netflix; Tekenen; Eten voetbal;muziek;vakantie;strand;vrienden bier drinken; muziek luisteren; sporten; Voetbal, Gamen, Design, Schoenen verzamelen Voetbal; Gamen; Bioscoop;Series kijken; Sporten; Lezen pianospelen; films kijken; simsen; voetballen; tennissen; sporten Honkbal; Auto's; Varen; zwemmen; pianospelen; dansen Muziek maken; muziek produceren; uitgaan met vrienden Skien, surfen, kitesurfen, wielrennen voetbal, gezelligheid, kleding Muziek;Games; Tekenen; gamen(nintendo); lezen; wandelen;
Schilderen en winkelen netflix; festival; shoppen tennis Chillen Lopen Volleybal; graphic design; basketbal Reizen; zwemmen; muziek luisteren vormgeven; gamen; tafeltennis; bioscoop Graffiti, snowboarden; films kijken; koken; reizen Gamen; Lezen rollerskaten;snowboarden;tekenen;tv kijken;drankjes doen Gamen; relaxen;hockey;biertjedrinken Coderen; Tennis; Voetbalwedstrijden analyseren Tekenen, gamen, lezen, schrijven Fotografie; plantenverzorging; slapen; festivalbezoeken Chillen, sporten, uitgaan gamen; leven Gamen; Serie kijken; terrass pakken hockey;netflix;uitgaan voetballen, feesten Netflixen, vrienden meeten, reizen vliegvissen; programmeren; reizen; netflix; dansen; uit gaan; wandelen eten, bios pakken, muziek luisteren, dansen op festivals, rijden Fotografie;DJ Netflix, fitness Netflix; borrelen; slapen muziek; slapen; films; chillen Voetbal gamen; wandelen; fietsen door mooie gebieden; leuke dingen met vrienden; festival bezoeken; koffie drinken; veel planten verzamelen voetballen, boxen, tekenen, dansen, zingen Voetbal;Mountainbiking;Computer-hardware;Handel in technologie;Video-gamen;Meubel-restoraties;Sci-Fi boeken lezen;Japanse cultuur; Tekenen; muziek maken slapen, films kijken Gamen, afspreken met vrienden, uitgaan Wielrennen; Voetballen; Gitaarspelen Voetballen;netflixen:fifa Series kijken ; Muziek luisteren ; Afspreken met mensen ; Festivallen bezoeken ; Lekker eten gamen; netflix kijken; sporten Schilderen; computeren Sporten;computeren Tekenen; Serie's kijken; Drankje drinken Series kijken; Tekenen Films, muziek, games Fitness; Voetbal; Tennis; Uitgaan; Tekenen Muziek luisteren en zoeken Gamen Hockey Drummen; Gamen; Chillen Gamen, karten tekenen; voetballen Zingen; Gitaar spelen; Fotograferen Basketbal;uitgaan skateboarden, fotograferen, filmen, drummen Hobbies zijn voor de delusionals Gitaar spelen; gamen; waterpolo; wandelen; reizen Feesten ; borrelen ; netflixen ; vakantie Motorrijden;Gamen Fitness, Dichten ; blowen Games, tekenen, gitaar, muziek maken Films en series
I started off by creating a main function in which I clean all my data.
I then began splitting the entries at every linebreak;
let splitData = enqueteData.split("\n")
Some people used ; to seperate their entries, others used a ,, a couple others even just used the word "en".
I used the map method to go through every entry in the survey, replacing all ,'s with ;'s
.map(entry => entry.replace(',', ';')
I then started a method chain by following up the replace with a split to seperate one person's multiple hobby's. I used a regular expression with two cases to split on;
.split(/;| en /)
The next thing I wanted to tackle was to capitalize the first letter of each entry. I want to create a seperate function for this, to practice put reusable code in a seperate function. It is also in line with functional programming.
function cleaningData(enqueteData){
let splitData = enqueteData.split("\n")
.map(entry => entry.replace(',', ';')
.split(/;| en /)
.map(hobby => capitalizeFirstLetter(hobby)))
console.log(splitData);
}
function capitalizeFirstLetter(hobby){
hobby.charAt(0).toUpperCase()
}
cleaningData(enqueteData)
I tried to add a function that changes every first letter to uppercase, since a lot of entries are all in lowercase. This does not work as it turns all entries into undefined.
I wanted to set all characters to lowercase so I can easily filter out invalid entries and to set the first letter to uppercase.
function entryToLowerCase(splitData) {
let lowerCaseData = splitData.map(entry => entry.toLowerCase())
console.log(lowerCaseData);
}
I removed the second split; .split(/;| en /). I did this because this created seperate arrays in the main data array. I wanted to try and make it so the data can be used again in a similar format.
function capitalizeFirstLetter(lowerCaseData){
let capitalizedData = lowerCaseData.map(entry => entry.charAt(0).toUpperCase())
console.log(capitalizedData)
}
I continued with capitalizing the first letter of every entry. I tried using the map method to loop through all the entries and the charAt(0) to get the first letter of each entry. I set that letter to uppercase.
When I log the result, I only get the single changed letter in uppercase. I have to join the rest of the entry somehow.
function capitalizeFirstLetter(lowerCaseData){
let capitalizedLetters = lowerCaseData.map(entry => entry.charAt(0).toUpperCase())
let joinableData = lowerCaseData.map(entry => entry.slice(1))
let capitalizedData = []
capitalizedData.push(capitalizedLetters+joinableData)
console.log(capitalizedData)
}
I tried pushing the two arrays I want to combine in a single new array. This does not work, as it just pastes the arrays one after another. It doesn't combine them.
function capitalizeFirstLetter(lowerCaseData){
let capitalizedData = lowerCaseData.map(entry => entry.charAt(0).toUpperCase() + entry.slice(1))
console.log(capitalizedData)
}
I have to add the rest of the string to it to combine them. If I slice the original entry from the second character, I get the part of the entry I want to combine with the capitalized first letter. (This took me way too long to figure out)