Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a file (attached as an image) which I imported to Mathematica and only extracted the first and second column. My problem is that I want to extract the data beginning from the row where $A=0$. Assuming that the extraction of the 2 columns is called $s$ I could easily use Drop Drop[s, 13], but I want the same for more files in which the 0 is not always at the beginning of the 14th row. I think I should wrap it in a function of the empty entries, but I have no clue how to do it.

Does anyone have suggestions for what my approach should be?

Revamped image description

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

Your data will be stored as a list of lists, so I'm just approximating that by using random numbers and letting A be list element number one. Then I would do this:

data = RandomInteger[10, {20, 3}]
Drop[data, LengthWhile[data, #[[1]] != 0 &]]

The new list will always start with a line where A is zero, so for example:

{{0, 8, 10}, {1, 7, 9}, {5, 1, 5}, {2, 10, 0}, {8, 0, 6}, {3, 1,
3}, {1, 5, 0}, {1, 10, 9}, {4, 2, 8}, {8, 4, 1}, {4, 10, 10}, {0, 6,
2}, {8, 0, 0}, {8, 4, 10}, {1, 6, 0}, {6, 8, 1}, {9, 1, 9}}

share|improve this answer
add comment

The edited title rather contains a hint to an alternative: Position

SeedRandom[1];
data = RandomInteger[10, {20, 3}]~Prepend~{"x", "y", "z"};
Drop[data, Position[data, {0, __}, {1}, 1][[1, 1]] - 1]

(* {{0, 2, 6}, {4, 5, 4}, {3, 0, 1}, {3, 5, 3},
    {0, 3, 2}, {3, 9, 5}, {1, 5, 2}, {3, 9, 1},
    {0, 4, 4}, {1, 5, 2}, {7, 9, 9}, {8, 10, 0}, {10, 10, 7}} *)

It's pretty fast, but that's not likely to be an issue, unless the first zero occurs rather far down the spreadsheet.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.