Exclude rows in a dataframe based on matching values in rows from another dataframeAdd one row to pandas DataFrameFilter dataframe rows if value in column is in a set list of valuesUse a list of values to select rows from a pandas dataframeDelete column from pandas DataFrameHow to drop rows of Pandas DataFrame whose value in certain columns is NaNHow do I get the row count of a pandas DataFrame?How to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasDeleting DataFrame row in Pandas based on column valueGet list from pandas DataFrame column headers

Take elements from a list based on two criteria

Why haven't we yet tried accelerating a space station with people inside to a near light speed?

Why did Drogon spare this character?

Does French have the English "short i" vowel?

Why isn't Tyrion mentioned in the in-universe book "A Song of Ice and Fire"?

Gravitational Force Between Numbers

Can a person survive on blood in place of water?

Why does Bran want to find Drogon?

Manager questioning my time estimates for a project

Shorten or merge multiple lines of `&> /dev/null &`

Why is unzipped directory exactly 4.0k (much smaller than zipped file)?

Which European Languages are not Indo-European?

How do I get the ς (final sigma) symbol?

Dealing with spaghetti codebase, manager asks for things I can't deliver

Why would a rational buyer offer to buy with no conditions precedent?

My players want to grind XP but we're using landmark advancement

Natural Armour and Weapons

How do I superimpose two math symbols?

Gravitational effects of a single human body on the motion of planets

Public transport tickets in UK for two weeks

Need to read my home electrical Meter

Python program to take in two strings and print the larger string

How was Daenerys able to legitimise this character?

Dad jokes are fun



Exclude rows in a dataframe based on matching values in rows from another dataframe


Add one row to pandas DataFrameFilter dataframe rows if value in column is in a set list of valuesUse a list of values to select rows from a pandas dataframeDelete column from pandas DataFrameHow to drop rows of Pandas DataFrame whose value in certain columns is NaNHow do I get the row count of a pandas DataFrame?How to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasDeleting DataFrame row in Pandas based on column valueGet list from pandas DataFrame column headers






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








0















I have two dataframes (A and B). I want to remove all the rows in B where the values for columns Month, Year, Type, Name are an exact match.



Dataframe A



 Name Type Month Year country Amount Expiration Paid
0 EXTRON GOLD March 2019 CA 20000 2019-09-07 yes
0 LEAF SILVER March 2019 PL 4893 2019-02-02 yes
0 JMC GOLD March 2019 IN 7000 2020-01-16 no


Dataframe B



 Name Type Month Year country Amount Expiration Paid
0 JONS GOLD March 2018 PL 500 2019-10-17 yes
0 ABBY BRONZE March 2019 AU 60000 2019-02-02 yes
0 BUYT GOLD March 2018 BR 50 2018-03-22 no
0 EXTRON GOLD March 2019 CA 90000 2019-09-07 yes
0 JAYB PURPLE March 2019 PL 9.90 2018-04-20 yes
0 JMC GOLD March 2019 IN 6000 2020-01-16 no
0 JMC GOLD April 2019 IN 1000 2020-01-16 no


Desired Output:



Dataframe B



 Name Type Month Year country Amount Expiration Paid
0 JONS GOLD March 2018 PL 500 2019-10-17 yes
0 ABBY BRONZE March 2019 AU 60000 2019-02-02 yes
0 BUYT GOLD March 2018 BR 50 2018-03-22 no
0 JAYB PURPLE March 2019 PL 9.90 2018-04-20 yes
0 JMC GOLD April 2019 IN 1000 2020-01-16 no









share|improve this question




























    0















    I have two dataframes (A and B). I want to remove all the rows in B where the values for columns Month, Year, Type, Name are an exact match.



    Dataframe A



     Name Type Month Year country Amount Expiration Paid
    0 EXTRON GOLD March 2019 CA 20000 2019-09-07 yes
    0 LEAF SILVER March 2019 PL 4893 2019-02-02 yes
    0 JMC GOLD March 2019 IN 7000 2020-01-16 no


    Dataframe B



     Name Type Month Year country Amount Expiration Paid
    0 JONS GOLD March 2018 PL 500 2019-10-17 yes
    0 ABBY BRONZE March 2019 AU 60000 2019-02-02 yes
    0 BUYT GOLD March 2018 BR 50 2018-03-22 no
    0 EXTRON GOLD March 2019 CA 90000 2019-09-07 yes
    0 JAYB PURPLE March 2019 PL 9.90 2018-04-20 yes
    0 JMC GOLD March 2019 IN 6000 2020-01-16 no
    0 JMC GOLD April 2019 IN 1000 2020-01-16 no


    Desired Output:



    Dataframe B



     Name Type Month Year country Amount Expiration Paid
    0 JONS GOLD March 2018 PL 500 2019-10-17 yes
    0 ABBY BRONZE March 2019 AU 60000 2019-02-02 yes
    0 BUYT GOLD March 2018 BR 50 2018-03-22 no
    0 JAYB PURPLE March 2019 PL 9.90 2018-04-20 yes
    0 JMC GOLD April 2019 IN 1000 2020-01-16 no









    share|improve this question
























      0












      0








      0








      I have two dataframes (A and B). I want to remove all the rows in B where the values for columns Month, Year, Type, Name are an exact match.



      Dataframe A



       Name Type Month Year country Amount Expiration Paid
      0 EXTRON GOLD March 2019 CA 20000 2019-09-07 yes
      0 LEAF SILVER March 2019 PL 4893 2019-02-02 yes
      0 JMC GOLD March 2019 IN 7000 2020-01-16 no


      Dataframe B



       Name Type Month Year country Amount Expiration Paid
      0 JONS GOLD March 2018 PL 500 2019-10-17 yes
      0 ABBY BRONZE March 2019 AU 60000 2019-02-02 yes
      0 BUYT GOLD March 2018 BR 50 2018-03-22 no
      0 EXTRON GOLD March 2019 CA 90000 2019-09-07 yes
      0 JAYB PURPLE March 2019 PL 9.90 2018-04-20 yes
      0 JMC GOLD March 2019 IN 6000 2020-01-16 no
      0 JMC GOLD April 2019 IN 1000 2020-01-16 no


      Desired Output:



      Dataframe B



       Name Type Month Year country Amount Expiration Paid
      0 JONS GOLD March 2018 PL 500 2019-10-17 yes
      0 ABBY BRONZE March 2019 AU 60000 2019-02-02 yes
      0 BUYT GOLD March 2018 BR 50 2018-03-22 no
      0 JAYB PURPLE March 2019 PL 9.90 2018-04-20 yes
      0 JMC GOLD April 2019 IN 1000 2020-01-16 no









      share|improve this question














      I have two dataframes (A and B). I want to remove all the rows in B where the values for columns Month, Year, Type, Name are an exact match.



      Dataframe A



       Name Type Month Year country Amount Expiration Paid
      0 EXTRON GOLD March 2019 CA 20000 2019-09-07 yes
      0 LEAF SILVER March 2019 PL 4893 2019-02-02 yes
      0 JMC GOLD March 2019 IN 7000 2020-01-16 no


      Dataframe B



       Name Type Month Year country Amount Expiration Paid
      0 JONS GOLD March 2018 PL 500 2019-10-17 yes
      0 ABBY BRONZE March 2019 AU 60000 2019-02-02 yes
      0 BUYT GOLD March 2018 BR 50 2018-03-22 no
      0 EXTRON GOLD March 2019 CA 90000 2019-09-07 yes
      0 JAYB PURPLE March 2019 PL 9.90 2018-04-20 yes
      0 JMC GOLD March 2019 IN 6000 2020-01-16 no
      0 JMC GOLD April 2019 IN 1000 2020-01-16 no


      Desired Output:



      Dataframe B



       Name Type Month Year country Amount Expiration Paid
      0 JONS GOLD March 2018 PL 500 2019-10-17 yes
      0 ABBY BRONZE March 2019 AU 60000 2019-02-02 yes
      0 BUYT GOLD March 2018 BR 50 2018-03-22 no
      0 JAYB PURPLE March 2019 PL 9.90 2018-04-20 yes
      0 JMC GOLD April 2019 IN 1000 2020-01-16 no






      python pandas if-statement conditional






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 0:48









      TH14TH14

      669




      669






















          2 Answers
          2






          active

          oldest

          votes


















          2














          We can using merge here



          l=['Month', 'Year','Type', 'Name']
          B=B.merge(A[l],on=l,indicator=True,how='outer').loc[lambda x : x['_merge']=='left_only'].copy()
          # you can add drop here like B=B.drop('_merge',1)
          Name Type Month Year country Amount Expiration Paid _merge
          0 JONS GOLD March 2018 PL 500.0 2019-10-17 yes left_only
          1 ABBY BRONZE March 2019 AU 60000.0 2019-02-02 yes left_only
          2 BUYT GOLD March 2018 BR 50.0 2018-03-22 no left_only
          4 JAYB PURPLE March 2019 PL 9.9 2018-04-20 yes left_only
          6 JMC GOLD April 2019 IN 1000.0 2020-01-16 no left_only





          share|improve this answer






























            1














            I tried using MultiIndex for the same.



            cols =['Month', 'Year','Type', 'Name']
            index1 = pd.MultiIndex.from_arrays([df1[col] for col in cols])
            index2 = pd.MultiIndex.from_arrays([df2[col] for col in cols])
            df2 = df2.loc[~index2.isin(index1)]





            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%2f55319758%2fexclude-rows-in-a-dataframe-based-on-matching-values-in-rows-from-another-datafr%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              We can using merge here



              l=['Month', 'Year','Type', 'Name']
              B=B.merge(A[l],on=l,indicator=True,how='outer').loc[lambda x : x['_merge']=='left_only'].copy()
              # you can add drop here like B=B.drop('_merge',1)
              Name Type Month Year country Amount Expiration Paid _merge
              0 JONS GOLD March 2018 PL 500.0 2019-10-17 yes left_only
              1 ABBY BRONZE March 2019 AU 60000.0 2019-02-02 yes left_only
              2 BUYT GOLD March 2018 BR 50.0 2018-03-22 no left_only
              4 JAYB PURPLE March 2019 PL 9.9 2018-04-20 yes left_only
              6 JMC GOLD April 2019 IN 1000.0 2020-01-16 no left_only





              share|improve this answer



























                2














                We can using merge here



                l=['Month', 'Year','Type', 'Name']
                B=B.merge(A[l],on=l,indicator=True,how='outer').loc[lambda x : x['_merge']=='left_only'].copy()
                # you can add drop here like B=B.drop('_merge',1)
                Name Type Month Year country Amount Expiration Paid _merge
                0 JONS GOLD March 2018 PL 500.0 2019-10-17 yes left_only
                1 ABBY BRONZE March 2019 AU 60000.0 2019-02-02 yes left_only
                2 BUYT GOLD March 2018 BR 50.0 2018-03-22 no left_only
                4 JAYB PURPLE March 2019 PL 9.9 2018-04-20 yes left_only
                6 JMC GOLD April 2019 IN 1000.0 2020-01-16 no left_only





                share|improve this answer

























                  2












                  2








                  2







                  We can using merge here



                  l=['Month', 'Year','Type', 'Name']
                  B=B.merge(A[l],on=l,indicator=True,how='outer').loc[lambda x : x['_merge']=='left_only'].copy()
                  # you can add drop here like B=B.drop('_merge',1)
                  Name Type Month Year country Amount Expiration Paid _merge
                  0 JONS GOLD March 2018 PL 500.0 2019-10-17 yes left_only
                  1 ABBY BRONZE March 2019 AU 60000.0 2019-02-02 yes left_only
                  2 BUYT GOLD March 2018 BR 50.0 2018-03-22 no left_only
                  4 JAYB PURPLE March 2019 PL 9.9 2018-04-20 yes left_only
                  6 JMC GOLD April 2019 IN 1000.0 2020-01-16 no left_only





                  share|improve this answer













                  We can using merge here



                  l=['Month', 'Year','Type', 'Name']
                  B=B.merge(A[l],on=l,indicator=True,how='outer').loc[lambda x : x['_merge']=='left_only'].copy()
                  # you can add drop here like B=B.drop('_merge',1)
                  Name Type Month Year country Amount Expiration Paid _merge
                  0 JONS GOLD March 2018 PL 500.0 2019-10-17 yes left_only
                  1 ABBY BRONZE March 2019 AU 60000.0 2019-02-02 yes left_only
                  2 BUYT GOLD March 2018 BR 50.0 2018-03-22 no left_only
                  4 JAYB PURPLE March 2019 PL 9.9 2018-04-20 yes left_only
                  6 JMC GOLD April 2019 IN 1000.0 2020-01-16 no left_only






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 24 at 0:52









                  WeNYoBenWeNYoBen

                  135k84474




                  135k84474























                      1














                      I tried using MultiIndex for the same.



                      cols =['Month', 'Year','Type', 'Name']
                      index1 = pd.MultiIndex.from_arrays([df1[col] for col in cols])
                      index2 = pd.MultiIndex.from_arrays([df2[col] for col in cols])
                      df2 = df2.loc[~index2.isin(index1)]





                      share|improve this answer



























                        1














                        I tried using MultiIndex for the same.



                        cols =['Month', 'Year','Type', 'Name']
                        index1 = pd.MultiIndex.from_arrays([df1[col] for col in cols])
                        index2 = pd.MultiIndex.from_arrays([df2[col] for col in cols])
                        df2 = df2.loc[~index2.isin(index1)]





                        share|improve this answer

























                          1












                          1








                          1







                          I tried using MultiIndex for the same.



                          cols =['Month', 'Year','Type', 'Name']
                          index1 = pd.MultiIndex.from_arrays([df1[col] for col in cols])
                          index2 = pd.MultiIndex.from_arrays([df2[col] for col in cols])
                          df2 = df2.loc[~index2.isin(index1)]





                          share|improve this answer













                          I tried using MultiIndex for the same.



                          cols =['Month', 'Year','Type', 'Name']
                          index1 = pd.MultiIndex.from_arrays([df1[col] for col in cols])
                          index2 = pd.MultiIndex.from_arrays([df2[col] for col in cols])
                          df2 = df2.loc[~index2.isin(index1)]






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 24 at 7:20









                          LoochieLoochie

                          984311




                          984311



























                              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%2f55319758%2fexclude-rows-in-a-dataframe-based-on-matching-values-in-rows-from-another-datafr%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

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript