Pandas Groupby: Groupby conditional statementConverting a Pandas GroupBy object to DataFrameSelecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headersgrouping rows in list in pandas groupby

What is the incentive for curl to release the library for free?

Will tsunami waves travel forever if there was no land?

Error message with tabularx

Do I have to worry about players making “bad” choices on level up?

Does this extra sentence in the description of the warlock's Eyes of the Rune Keeper eldritch invocation appear in any official reference?

Is DC-DC (24v to 12v) Buck Conversion typically more efficient than AC-DC (110v to 12v) conversion?

What is the strongest case that can be made in favour of the UK regaining some control over fishing policy after Brexit?

Any examples of headwear for races with animal ears?

Mac Pro install disk keeps ejecting itself

Sci-fi novel series with instant travel between planets through gates. A river runs through the gates

What is the difference between `command a[bc]d` and `command `ab,cd`

How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?

How do I use proper grammar in the negation of "have not" for the following sentence translation?

a sore throat vs a strep throat vs strep throat

Why don't other Westeros houses use wildfire?

Why do Computer Science majors learn Calculus?

Why was Germany not as successful as other Europeans in establishing overseas colonies?

What does KSP mean?

Do I have an "anti-research" personality?

Is contacting this expert in the field something acceptable or would it be discourteous?

What is the relationship between spectral sequences and obstruction theory?

How to verbalise code in Mathematica?

How much cash can I safely carry into the USA and avoid civil forfeiture?

how to sum variables from file in bash



Pandas Groupby: Groupby conditional statement


Converting a Pandas GroupBy object to DataFrameSelecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headersgrouping rows in list in pandas groupby






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to identify the location of stops from gps data but need to account for some gps drift.



I have identified stops and isolated them into a new dataframe:



df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005) & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)

df2 = df.loc[(df['Stopped'] == True)]


Now I can label groups that have the exact match in coordinates using:



df2['StoppedEvent'] = df2.groupby(['LAT','LNG']).ngroup() 


But I want to group by the same conditions of Stopped. Something like this but that works:



df2['StoppedEvent'] = df2.groupby((['LAT','LNG']).diff().fillna(0).abs() <= 0.0005).ngroup() 









share|improve this question




























    0















    I am trying to identify the location of stops from gps data but need to account for some gps drift.



    I have identified stops and isolated them into a new dataframe:



    df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005) & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)

    df2 = df.loc[(df['Stopped'] == True)]


    Now I can label groups that have the exact match in coordinates using:



    df2['StoppedEvent'] = df2.groupby(['LAT','LNG']).ngroup() 


    But I want to group by the same conditions of Stopped. Something like this but that works:



    df2['StoppedEvent'] = df2.groupby((['LAT','LNG']).diff().fillna(0).abs() <= 0.0005).ngroup() 









    share|improve this question
























      0












      0








      0








      I am trying to identify the location of stops from gps data but need to account for some gps drift.



      I have identified stops and isolated them into a new dataframe:



      df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005) & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)

      df2 = df.loc[(df['Stopped'] == True)]


      Now I can label groups that have the exact match in coordinates using:



      df2['StoppedEvent'] = df2.groupby(['LAT','LNG']).ngroup() 


      But I want to group by the same conditions of Stopped. Something like this but that works:



      df2['StoppedEvent'] = df2.groupby((['LAT','LNG']).diff().fillna(0).abs() <= 0.0005).ngroup() 









      share|improve this question














      I am trying to identify the location of stops from gps data but need to account for some gps drift.



      I have identified stops and isolated them into a new dataframe:



      df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005) & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)

      df2 = df.loc[(df['Stopped'] == True)]


      Now I can label groups that have the exact match in coordinates using:



      df2['StoppedEvent'] = df2.groupby(['LAT','LNG']).ngroup() 


      But I want to group by the same conditions of Stopped. Something like this but that works:



      df2['StoppedEvent'] = df2.groupby((['LAT','LNG']).diff().fillna(0).abs() <= 0.0005).ngroup() 






      pandas group-by pandas-groupby latitude-longitude






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 18:39









      acrowacrow

      62




      62






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I would do something like the following:



          df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005)
          & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)
          df["Stopped_Group"] = (~df["Stopped"]).cumsum()
          df2 = df.loc[df['Stopped']]


          Now you'll have a column, "Stopped_Group", which is constant within a set of rows that are close to each other as determined by your logic. In the original dataframe, df, this column won't have any meaning for rows that correspond to motion.



          To get your desired output (if I understand you correctly), do something like the following:



          df2["Stopped_Duration"] = df2.groupby("Stopped_Group").transform("size")





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55305938%2fpandas-groupby-groupby-conditional-statement%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I would do something like the following:



            df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005)
            & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)
            df["Stopped_Group"] = (~df["Stopped"]).cumsum()
            df2 = df.loc[df['Stopped']]


            Now you'll have a column, "Stopped_Group", which is constant within a set of rows that are close to each other as determined by your logic. In the original dataframe, df, this column won't have any meaning for rows that correspond to motion.



            To get your desired output (if I understand you correctly), do something like the following:



            df2["Stopped_Duration"] = df2.groupby("Stopped_Group").transform("size")





            share|improve this answer



























              0














              I would do something like the following:



              df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005)
              & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)
              df["Stopped_Group"] = (~df["Stopped"]).cumsum()
              df2 = df.loc[df['Stopped']]


              Now you'll have a column, "Stopped_Group", which is constant within a set of rows that are close to each other as determined by your logic. In the original dataframe, df, this column won't have any meaning for rows that correspond to motion.



              To get your desired output (if I understand you correctly), do something like the following:



              df2["Stopped_Duration"] = df2.groupby("Stopped_Group").transform("size")





              share|improve this answer

























                0












                0








                0







                I would do something like the following:



                df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005)
                & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)
                df["Stopped_Group"] = (~df["Stopped"]).cumsum()
                df2 = df.loc[df['Stopped']]


                Now you'll have a column, "Stopped_Group", which is constant within a set of rows that are close to each other as determined by your logic. In the original dataframe, df, this column won't have any meaning for rows that correspond to motion.



                To get your desired output (if I understand you correctly), do something like the following:



                df2["Stopped_Duration"] = df2.groupby("Stopped_Group").transform("size")





                share|improve this answer













                I would do something like the following:



                df['Stopped'] = (df.groupby('DAY')['LAT'].diff().abs() <= 0.0005)
                & (df.groupby('DAY')['LNG'].diff().abs() <= 0.0005)
                df["Stopped_Group"] = (~df["Stopped"]).cumsum()
                df2 = df.loc[df['Stopped']]


                Now you'll have a column, "Stopped_Group", which is constant within a set of rows that are close to each other as determined by your logic. In the original dataframe, df, this column won't have any meaning for rows that correspond to motion.



                To get your desired output (if I understand you correctly), do something like the following:



                df2["Stopped_Duration"] = df2.groupby("Stopped_Group").transform("size")






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 18:48









                PMendePMende

                1,9101613




                1,9101613





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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.

                    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%2fstackoverflow.com%2fquestions%2f55305938%2fpandas-groupby-groupby-conditional-statement%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현