Select row of data if next row contains zeroData Table Manipulation in MathematicaData Table Manipulation in...

What is the difference between nullifying your vote and not going to vote at all?

My player wants to cast multiple charges of magic missile from a wand

Is there an evolutionary advantage to having two heads?

Expenditure in Poland - Forex doesn't have Zloty

In what episode of TOS did a character on the bridge make a comment about raising the number 1 to some power?

Socratic Paradox

How was Apollo supposed to rendezvous in the case of a lunar abort?

Draw a checker pattern with a black X in the center

The qvolume of an integer

How to properly maintain eye contact with people that have distinctive facial features?

Why do Russians call their women expensive ("дорогая")?

What is the 中 in ダウンロード中?

Can a rogue effectively triple their speed by combining Dash and Ready?

Is this light switch installation safe and legal?

Fastest way to perform complex search on pandas dataframe

find the Integer value after a string from a file

Where can I find the list of all tendons in the human body?

Can a helicopter mask itself from Radar?

Is it possible to kill all life on Earth?

Why does the UK have more political parties than the US?

Biblical Basis for 400 years of silence between old and new testament

Uncommanded roll at high speed

Infinitely many hats

If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?



Select row of data if next row contains zero


Data Table Manipulation in MathematicaData Table Manipulation in Mathematica: Step 2Using levels in MapIndexedCompute the evolution of percentages from a data fileGenerate a new listSort columns in a TableFormmaking two columns from 1D-horizontal dataLoading and formatting data for plotting standard deviation bars on top of dataSelect rows of data that satisfies both conditions simultaneouslySelecting matrices based on existence of unique column and row of all equal terms













6












$begingroup$


I am a new user of Mathematica, and just faced a problem.
I have a data set of three columns, and want to select only those rows that go before the rows, which don't contain 0 in the third column.
Eventually I want to create a new data set containing only these selected rows.



Can it be performed in Mathematica?
Thank you in advance!



(edited)










share|improve this question









New contributor



Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$

















    6












    $begingroup$


    I am a new user of Mathematica, and just faced a problem.
    I have a data set of three columns, and want to select only those rows that go before the rows, which don't contain 0 in the third column.
    Eventually I want to create a new data set containing only these selected rows.



    Can it be performed in Mathematica?
    Thank you in advance!



    (edited)










    share|improve this question









    New contributor



    Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    $endgroup$















      6












      6








      6





      $begingroup$


      I am a new user of Mathematica, and just faced a problem.
      I have a data set of three columns, and want to select only those rows that go before the rows, which don't contain 0 in the third column.
      Eventually I want to create a new data set containing only these selected rows.



      Can it be performed in Mathematica?
      Thank you in advance!



      (edited)










      share|improve this question









      New contributor



      Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      $endgroup$




      I am a new user of Mathematica, and just faced a problem.
      I have a data set of three columns, and want to select only those rows that go before the rows, which don't contain 0 in the third column.
      Eventually I want to create a new data set containing only these selected rows.



      Can it be performed in Mathematica?
      Thank you in advance!



      (edited)







      list-manipulation






      share|improve this question









      New contributor



      Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 7 hours ago









      user64494

      3,90211323




      3,90211323






      New contributor



      Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 10 hours ago









      AnnaAnna

      313




      313




      New contributor



      Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          3 Answers
          3






          active

          oldest

          votes


















          10












          $begingroup$

          You can use SequenceCases to define a pattern of two elements, the second of which has a 0 in the second column.



          data = {{1, 2}, {8, 4}, {5, 0}, {3, 2}, {8, 9}, {7, 0}, {2, 3}};

          SequenceCases[data, {a_, {___, 0}} :> a]
          (* {{8, 4}, {8, 9}} *)


          Here {a_, {___, 0}} is the pattern for two rows, and the :> a says that we want to extract the first part of the pattern.






          share|improve this answer











          $endgroup$













          • $begingroup$
            Great solution! There's no need to name b, you can use the pattern {a_, {_, 0}} or even {a_, {___, 0}} (to be more flexible, see @kglr's comment below other solution).
            $endgroup$
            – Roman
            8 hours ago












          • $begingroup$
            Thanks for the suggestions!
            $endgroup$
            – Jason B.
            7 hours ago



















          7












          $begingroup$

          You can also use ReplaceList:



          data = {{1, 1, 2}, {2, 8, 4}, {3, 5, 0}, {4, 3, 2}, {5, 8, 9}, {6, 7, 0}, {7, 2, 3}};
          ReplaceList[data, {___, a_, {__, 0}, ___} :> a]



          {{2, 8, 4}, {5, 8, 9}}




          Or combinations of



          Extract and Position:



          Extract[data, Position[data[[2 ;;, -1]], 0]]



          {{2, 8, 4}, {5, 8, 9}}




          PositionIndex and Part:



          data[[PositionIndex[data[[2 ;;, -1]]][0]]]



          {{2, 8, 4}, {5, 8, 9}}







          share|improve this answer











          $endgroup$













          • $begingroup$
            Thank you a lot!! It works perfectly for my data set. I wonder now how the command Extract would work for 3 columns (zero value is in the 3rd column)?
            $endgroup$
            – Anna
            9 hours ago












          • $begingroup$
            @Anna, made a small change ( replaced {_,0} with {__,0}) so that all methods should work for any number of columns (as long as the criterion is "the last column is of the next row is 0")
            $endgroup$
            – kglr
            9 hours ago










          • $begingroup$
            @kglr For what it's worth: Cases[Split[data, #[[2]] != 0 &], {, a_, {, 0}} :> a] returns {} for me.
            $endgroup$
            – Christopher Lamb
            6 hours ago










          • $begingroup$
            @ChristopherLamb, thank you; it is fixed now.
            $endgroup$
            – kglr
            6 hours ago



















          0












          $begingroup$

          data //Pick[Most@#, #[[2;;,3]],0]&



          {{2, 8, 4}, {5, 8, 9}}







          share|improve this answer











          $endgroup$














            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "387"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Anna is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199260%2fselect-row-of-data-if-next-row-contains-zero%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            10












            $begingroup$

            You can use SequenceCases to define a pattern of two elements, the second of which has a 0 in the second column.



            data = {{1, 2}, {8, 4}, {5, 0}, {3, 2}, {8, 9}, {7, 0}, {2, 3}};

            SequenceCases[data, {a_, {___, 0}} :> a]
            (* {{8, 4}, {8, 9}} *)


            Here {a_, {___, 0}} is the pattern for two rows, and the :> a says that we want to extract the first part of the pattern.






            share|improve this answer











            $endgroup$













            • $begingroup$
              Great solution! There's no need to name b, you can use the pattern {a_, {_, 0}} or even {a_, {___, 0}} (to be more flexible, see @kglr's comment below other solution).
              $endgroup$
              – Roman
              8 hours ago












            • $begingroup$
              Thanks for the suggestions!
              $endgroup$
              – Jason B.
              7 hours ago
















            10












            $begingroup$

            You can use SequenceCases to define a pattern of two elements, the second of which has a 0 in the second column.



            data = {{1, 2}, {8, 4}, {5, 0}, {3, 2}, {8, 9}, {7, 0}, {2, 3}};

            SequenceCases[data, {a_, {___, 0}} :> a]
            (* {{8, 4}, {8, 9}} *)


            Here {a_, {___, 0}} is the pattern for two rows, and the :> a says that we want to extract the first part of the pattern.






            share|improve this answer











            $endgroup$













            • $begingroup$
              Great solution! There's no need to name b, you can use the pattern {a_, {_, 0}} or even {a_, {___, 0}} (to be more flexible, see @kglr's comment below other solution).
              $endgroup$
              – Roman
              8 hours ago












            • $begingroup$
              Thanks for the suggestions!
              $endgroup$
              – Jason B.
              7 hours ago














            10












            10








            10





            $begingroup$

            You can use SequenceCases to define a pattern of two elements, the second of which has a 0 in the second column.



            data = {{1, 2}, {8, 4}, {5, 0}, {3, 2}, {8, 9}, {7, 0}, {2, 3}};

            SequenceCases[data, {a_, {___, 0}} :> a]
            (* {{8, 4}, {8, 9}} *)


            Here {a_, {___, 0}} is the pattern for two rows, and the :> a says that we want to extract the first part of the pattern.






            share|improve this answer











            $endgroup$



            You can use SequenceCases to define a pattern of two elements, the second of which has a 0 in the second column.



            data = {{1, 2}, {8, 4}, {5, 0}, {3, 2}, {8, 9}, {7, 0}, {2, 3}};

            SequenceCases[data, {a_, {___, 0}} :> a]
            (* {{8, 4}, {8, 9}} *)


            Here {a_, {___, 0}} is the pattern for two rows, and the :> a says that we want to extract the first part of the pattern.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 7 hours ago

























            answered 10 hours ago









            Jason B.Jason B.

            49.6k391199




            49.6k391199












            • $begingroup$
              Great solution! There's no need to name b, you can use the pattern {a_, {_, 0}} or even {a_, {___, 0}} (to be more flexible, see @kglr's comment below other solution).
              $endgroup$
              – Roman
              8 hours ago












            • $begingroup$
              Thanks for the suggestions!
              $endgroup$
              – Jason B.
              7 hours ago


















            • $begingroup$
              Great solution! There's no need to name b, you can use the pattern {a_, {_, 0}} or even {a_, {___, 0}} (to be more flexible, see @kglr's comment below other solution).
              $endgroup$
              – Roman
              8 hours ago












            • $begingroup$
              Thanks for the suggestions!
              $endgroup$
              – Jason B.
              7 hours ago
















            $begingroup$
            Great solution! There's no need to name b, you can use the pattern {a_, {_, 0}} or even {a_, {___, 0}} (to be more flexible, see @kglr's comment below other solution).
            $endgroup$
            – Roman
            8 hours ago






            $begingroup$
            Great solution! There's no need to name b, you can use the pattern {a_, {_, 0}} or even {a_, {___, 0}} (to be more flexible, see @kglr's comment below other solution).
            $endgroup$
            – Roman
            8 hours ago














            $begingroup$
            Thanks for the suggestions!
            $endgroup$
            – Jason B.
            7 hours ago




            $begingroup$
            Thanks for the suggestions!
            $endgroup$
            – Jason B.
            7 hours ago











            7












            $begingroup$

            You can also use ReplaceList:



            data = {{1, 1, 2}, {2, 8, 4}, {3, 5, 0}, {4, 3, 2}, {5, 8, 9}, {6, 7, 0}, {7, 2, 3}};
            ReplaceList[data, {___, a_, {__, 0}, ___} :> a]



            {{2, 8, 4}, {5, 8, 9}}




            Or combinations of



            Extract and Position:



            Extract[data, Position[data[[2 ;;, -1]], 0]]



            {{2, 8, 4}, {5, 8, 9}}




            PositionIndex and Part:



            data[[PositionIndex[data[[2 ;;, -1]]][0]]]



            {{2, 8, 4}, {5, 8, 9}}







            share|improve this answer











            $endgroup$













            • $begingroup$
              Thank you a lot!! It works perfectly for my data set. I wonder now how the command Extract would work for 3 columns (zero value is in the 3rd column)?
              $endgroup$
              – Anna
              9 hours ago












            • $begingroup$
              @Anna, made a small change ( replaced {_,0} with {__,0}) so that all methods should work for any number of columns (as long as the criterion is "the last column is of the next row is 0")
              $endgroup$
              – kglr
              9 hours ago










            • $begingroup$
              @kglr For what it's worth: Cases[Split[data, #[[2]] != 0 &], {, a_, {, 0}} :> a] returns {} for me.
              $endgroup$
              – Christopher Lamb
              6 hours ago










            • $begingroup$
              @ChristopherLamb, thank you; it is fixed now.
              $endgroup$
              – kglr
              6 hours ago
















            7












            $begingroup$

            You can also use ReplaceList:



            data = {{1, 1, 2}, {2, 8, 4}, {3, 5, 0}, {4, 3, 2}, {5, 8, 9}, {6, 7, 0}, {7, 2, 3}};
            ReplaceList[data, {___, a_, {__, 0}, ___} :> a]



            {{2, 8, 4}, {5, 8, 9}}




            Or combinations of



            Extract and Position:



            Extract[data, Position[data[[2 ;;, -1]], 0]]



            {{2, 8, 4}, {5, 8, 9}}




            PositionIndex and Part:



            data[[PositionIndex[data[[2 ;;, -1]]][0]]]



            {{2, 8, 4}, {5, 8, 9}}







            share|improve this answer











            $endgroup$













            • $begingroup$
              Thank you a lot!! It works perfectly for my data set. I wonder now how the command Extract would work for 3 columns (zero value is in the 3rd column)?
              $endgroup$
              – Anna
              9 hours ago












            • $begingroup$
              @Anna, made a small change ( replaced {_,0} with {__,0}) so that all methods should work for any number of columns (as long as the criterion is "the last column is of the next row is 0")
              $endgroup$
              – kglr
              9 hours ago










            • $begingroup$
              @kglr For what it's worth: Cases[Split[data, #[[2]] != 0 &], {, a_, {, 0}} :> a] returns {} for me.
              $endgroup$
              – Christopher Lamb
              6 hours ago










            • $begingroup$
              @ChristopherLamb, thank you; it is fixed now.
              $endgroup$
              – kglr
              6 hours ago














            7












            7








            7





            $begingroup$

            You can also use ReplaceList:



            data = {{1, 1, 2}, {2, 8, 4}, {3, 5, 0}, {4, 3, 2}, {5, 8, 9}, {6, 7, 0}, {7, 2, 3}};
            ReplaceList[data, {___, a_, {__, 0}, ___} :> a]



            {{2, 8, 4}, {5, 8, 9}}




            Or combinations of



            Extract and Position:



            Extract[data, Position[data[[2 ;;, -1]], 0]]



            {{2, 8, 4}, {5, 8, 9}}




            PositionIndex and Part:



            data[[PositionIndex[data[[2 ;;, -1]]][0]]]



            {{2, 8, 4}, {5, 8, 9}}







            share|improve this answer











            $endgroup$



            You can also use ReplaceList:



            data = {{1, 1, 2}, {2, 8, 4}, {3, 5, 0}, {4, 3, 2}, {5, 8, 9}, {6, 7, 0}, {7, 2, 3}};
            ReplaceList[data, {___, a_, {__, 0}, ___} :> a]



            {{2, 8, 4}, {5, 8, 9}}




            Or combinations of



            Extract and Position:



            Extract[data, Position[data[[2 ;;, -1]], 0]]



            {{2, 8, 4}, {5, 8, 9}}




            PositionIndex and Part:



            data[[PositionIndex[data[[2 ;;, -1]]][0]]]



            {{2, 8, 4}, {5, 8, 9}}








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 1 hour ago

























            answered 10 hours ago









            kglrkglr

            195k10216438




            195k10216438












            • $begingroup$
              Thank you a lot!! It works perfectly for my data set. I wonder now how the command Extract would work for 3 columns (zero value is in the 3rd column)?
              $endgroup$
              – Anna
              9 hours ago












            • $begingroup$
              @Anna, made a small change ( replaced {_,0} with {__,0}) so that all methods should work for any number of columns (as long as the criterion is "the last column is of the next row is 0")
              $endgroup$
              – kglr
              9 hours ago










            • $begingroup$
              @kglr For what it's worth: Cases[Split[data, #[[2]] != 0 &], {, a_, {, 0}} :> a] returns {} for me.
              $endgroup$
              – Christopher Lamb
              6 hours ago










            • $begingroup$
              @ChristopherLamb, thank you; it is fixed now.
              $endgroup$
              – kglr
              6 hours ago


















            • $begingroup$
              Thank you a lot!! It works perfectly for my data set. I wonder now how the command Extract would work for 3 columns (zero value is in the 3rd column)?
              $endgroup$
              – Anna
              9 hours ago












            • $begingroup$
              @Anna, made a small change ( replaced {_,0} with {__,0}) so that all methods should work for any number of columns (as long as the criterion is "the last column is of the next row is 0")
              $endgroup$
              – kglr
              9 hours ago










            • $begingroup$
              @kglr For what it's worth: Cases[Split[data, #[[2]] != 0 &], {, a_, {, 0}} :> a] returns {} for me.
              $endgroup$
              – Christopher Lamb
              6 hours ago










            • $begingroup$
              @ChristopherLamb, thank you; it is fixed now.
              $endgroup$
              – kglr
              6 hours ago
















            $begingroup$
            Thank you a lot!! It works perfectly for my data set. I wonder now how the command Extract would work for 3 columns (zero value is in the 3rd column)?
            $endgroup$
            – Anna
            9 hours ago






            $begingroup$
            Thank you a lot!! It works perfectly for my data set. I wonder now how the command Extract would work for 3 columns (zero value is in the 3rd column)?
            $endgroup$
            – Anna
            9 hours ago














            $begingroup$
            @Anna, made a small change ( replaced {_,0} with {__,0}) so that all methods should work for any number of columns (as long as the criterion is "the last column is of the next row is 0")
            $endgroup$
            – kglr
            9 hours ago




            $begingroup$
            @Anna, made a small change ( replaced {_,0} with {__,0}) so that all methods should work for any number of columns (as long as the criterion is "the last column is of the next row is 0")
            $endgroup$
            – kglr
            9 hours ago












            $begingroup$
            @kglr For what it's worth: Cases[Split[data, #[[2]] != 0 &], {, a_, {, 0}} :> a] returns {} for me.
            $endgroup$
            – Christopher Lamb
            6 hours ago




            $begingroup$
            @kglr For what it's worth: Cases[Split[data, #[[2]] != 0 &], {, a_, {, 0}} :> a] returns {} for me.
            $endgroup$
            – Christopher Lamb
            6 hours ago












            $begingroup$
            @ChristopherLamb, thank you; it is fixed now.
            $endgroup$
            – kglr
            6 hours ago




            $begingroup$
            @ChristopherLamb, thank you; it is fixed now.
            $endgroup$
            – kglr
            6 hours ago











            0












            $begingroup$

            data //Pick[Most@#, #[[2;;,3]],0]&



            {{2, 8, 4}, {5, 8, 9}}







            share|improve this answer











            $endgroup$


















              0












              $begingroup$

              data //Pick[Most@#, #[[2;;,3]],0]&



              {{2, 8, 4}, {5, 8, 9}}







              share|improve this answer











              $endgroup$
















                0












                0








                0





                $begingroup$

                data //Pick[Most@#, #[[2;;,3]],0]&



                {{2, 8, 4}, {5, 8, 9}}







                share|improve this answer











                $endgroup$



                data //Pick[Most@#, #[[2;;,3]],0]&



                {{2, 8, 4}, {5, 8, 9}}








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 hour ago

























                answered 6 hours ago









                user1066user1066

                6,19822033




                6,19822033






















                    Anna is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Anna is a new contributor. Be nice, and check out our Code of Conduct.













                    Anna is a new contributor. Be nice, and check out our Code of Conduct.












                    Anna is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Mathematica Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199260%2fselect-row-of-data-if-next-row-contains-zero%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...