0
$\begingroup$

I have imported data. {{...},{...},{...},...{...}}

Here a screenshot: enter image description here

As you can see there are empty entires {,,,,,,}

How can I delete those entries ?

$\endgroup$
2
$\begingroup$

If you want to delete rows that only consist of empty strings:

DeleteCases[data, {"" ..}]

"" .. is a pattern for "1 or more empty strings in a row". .. is shorthand for Repeated.

$\endgroup$
  • $\begingroup$ Very elegant ! Good explenation! Thank you. $\endgroup$ – henry Aug 9 '16 at 15:35
  • $\begingroup$ DeleteCases[{{1,""}, {2,""}, {}}, {"" ..}] doesn't give me the same result as I have in my answer. Perhaps I am missing something. $\endgroup$ – Eric Brown Aug 9 '16 at 15:44
1
$\begingroup$

Those are probably empty strings, so:

DeleteCases[{1,"",""}, ""]

will probably work for a single list. For lists of lists, you can use Map:

Map[ DeleteCases[#, ""] &, listOfLists]

If you would like to delete remaining empty rows, you can augment this with another DeleteCases:

DeleteCases[
  Map[ DeleteCases[#, ""] &, listOfLists]
, {}]
$\endgroup$
  • $\begingroup$ Hmm ... it is not working. It is working for your problem, but in my case I have rows witch are only empty strings. $\endgroup$ – henry Aug 9 '16 at 15:20
  • $\begingroup$ Please try my edited response. $\endgroup$ – Eric Brown Aug 9 '16 at 15:24
  • $\begingroup$ Very close... it delets all the empty entries but leaves the brakets {}. I have found a way to get rid of them. DeleteCases[Map[DeleteCases[#, ""] &, resMat], {}] $\endgroup$ – henry Aug 9 '16 at 15:27
  • $\begingroup$ please add my solution to your response, so that I can validate your answer. :) $\endgroup$ – henry Aug 9 '16 at 15:28
  • $\begingroup$ I made the edit. $\endgroup$ – Eric Brown Aug 9 '16 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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