Prometheus Posted November 30, 2015 Share Posted November 30, 2015 I'm trying to learn Mathematica, but the support community is a bit sparse. Hoping someone here could help with a particular problem. It's from the Kaggle Titanic data set: {{"Name"}, {"Braund,", "Mr.", "Owen", "Harris"}, {"Cumings,", "Mrs.", "John", "Bradley", "(Florence", "Briggs", "Thayer)"}, {"Heikkinen,", "Miss.", "Laina"}, {"Futrelle,", "Mrs.", "Jacques", "Heath", "(Lily", "May", "Peel)"}, {"Allen,", "Mr.", "William", "Henry"}, {"Moran,", "Mr.", "James"}, {"McCarthy,", "Mr.", "Timothy", "J"}, {"Palsson,", "Master.", "Gosta", "Leonard"}, {"Johnson,", "Mrs.", "Oscar", "W", "(Elisabeth", "Vilhelmina", "Berg)"}} What i want to do is isolate the first names of all passengers - this corresponds to the third word in each element, so {"Braund,", "Mr.", "Owen", "Harris"} = "Owen". I have been unable to find a way to do so. The closest i have come is putting the data in table form, the third column of which is first names but then trying to take this column with: data[[All, 3]] // TableForm doesn't work seemingly because Mathematica still doesn't recognise the column as a column - though who knows what Mathematica is doing behind the scene. Any help very welcome. Link to comment Share on other sites More sharing options...
DevilSolution Posted December 1, 2015 Share Posted December 1, 2015 (edited) I dont know Mathematica personally so i cant create you any code as i dont know what functions it comes shipped with however if you wanted to go back to basics couldnt you parse the whole string within a function that "thows" the brackets and counts the words, once you get to the third store it in an array? what format is a data set? its own object type? Edited December 1, 2015 by DevilSolution Link to comment Share on other sites More sharing options...
Prometheus Posted December 4, 2015 Author Share Posted December 4, 2015 The names are stored in a list of strings. There is a function called StringSplit which splits a string into substrings from which i got a nice table, but i can;t find a way of getting mathematica to work with the substrings to do further work. Mathematica is quite different to other languages i'm learning (R and Python) and i'm beginning to think it isn't worth it. Link to comment Share on other sites More sharing options...
Prometheus Posted December 4, 2015 Author Share Posted December 4, 2015 Did it this way in case anyone else is wondering (the dataset is called TitanicData): name := TitanicData[[All, 4]] seperatenames = Map[stringSplit, Rest[name]]; seperatenames[[All, 3]] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now