Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This is an offshoot from my previous question about dealing with large datasets in Mathematica. I think it might provide more value to more people as a separate question.

I'd like to know how people are dealing with data wrangling of messy data in Mathematica.

I'm dealing with data that mostly has the same columns, but can be shifted about a bit, sometimes have extra columns added. Mathematica, doesn't seem to have a record or structure type, only lists and matrices. How are people dealing with this? I've taken to loading my data into an SQL database, but even this is suboptimal - for my classifier I have to make sure I select the same fields, in the same order, in the same offset in a list. Difficult as sometimes my data is in similar, but slightly different forms.

Example. Notice there are additions, transpositions, and a missing field in the second. This is the same data, but in a different form.

One dataset: col1, col2, col3, col4, col5.

another: cola, colb, col2, col3, col5, col1.

EDIT: For the sort of work I'm doing the trouble I run into is matching up the columns/fields from source1 to the same columns in source2. In different sources of data the columns move about, some are some deletions/additions.

Mathematica works mostly with lists, not records or structures so I can't say somefunc[samp1.tempdata, samp2.tempdata]. Records, and the ability to iterate over the members of a record would honestly be a godsend.

share|improve this question
2  
It would be easier to answer if you provide some small toy example for 2 data sets and also state which operations you have to perform on them. – Leonid Shifrin Dec 11 '12 at 18:43
1  
One simple record representation is the rule list: {"col1"->val1,"col2"->val2,...}. You can extract a field "col3" with "col3" /. rules. – Joel Klein Dec 11 '12 at 19:07
I'd say that there are lots of people using Mathematica to deal with this type of issue precisely because so much data simply comes this way. Web-scraped data, for example, is frequently unstructured and requires a lot of massaging. – Mark McClure Dec 11 '12 at 19:10
3  
Rule lists function as hash tables. You can make them hashier, so to speak, by wrapping them in Dispatch, that improves lookup speed. But rule lists with "field" /. object give you that random-access/don't-care-about-where-the-field-is property that it seems you're looking for. – Joel Klein Dec 11 '12 at 20:30
2  
I think the question could be better answered by clarifying the question. As it stands, "how do people deal with messy data" is pretty general, and more of a community Twiki because there are different kinds of messiness. But your example suggests we could narrow the question to the already linked one on structs. – Joel Klein Dec 11 '12 at 20:35
show 3 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.