Jump to content

Taking words from an element in Mathematica

Featured Replies

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.

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 by DevilSolution

  • Author

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.

 

  • Author

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]]

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.