Comparing OrderDict of DataFrames












0















I am facing a comparing problem, this is my code:



import pandas as pd
from collections import OrderedDict
from pandas.util.testing import assert_frame_equal

df1 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
'three' : pd.Series([1., 2., 3., 4., 5.], index=['a', 'b', 'c', 'd','e'])}

df2 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
'three' : pd.Series([1., 2., 3., 4., 5.], index=['a', 'b', 'c', 'd','e'])}
od = OrderedDict()
od['a'] = pd.DataFrame(df1)
od['b'] = pd.DataFrame(df1)
od['c'] = pd.DataFrame(df1)
od['d'] = pd.DataFrame(df1)

od2 = OrderedDict()
od2['a'] = pd.DataFrame(df2)
od2['b'] = pd.DataFrame(df2)
od2['c'] = pd.DataFrame(df2)
od2['d'] = pd.DataFrame(df2)

test = assert_frame_equal(od, od2)
print(test)


I have 2 OrderedDict made of pandas DataFrames and I would like to analyze if the single elements inside the DataFrames are equal.



I found the function assert_frame_equal that works perfectly when it comes to compare 2 DataFrames, but gives this error with OrderedDict:




AssertionError: DataFrame Expected type class
'pandas.core.frame.DataFrame', found class
'collections.OrderedDict' instead




Is there any solution or workaround to this? Take into account that I necessarily start from an OrderedDict and unfortunately I cannot change that.



Thanks so much in advance any help/hint on this issue.










share|improve this question



























    0















    I am facing a comparing problem, this is my code:



    import pandas as pd
    from collections import OrderedDict
    from pandas.util.testing import assert_frame_equal

    df1 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
    'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
    'three' : pd.Series([1., 2., 3., 4., 5.], index=['a', 'b', 'c', 'd','e'])}

    df2 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
    'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
    'three' : pd.Series([1., 2., 3., 4., 5.], index=['a', 'b', 'c', 'd','e'])}
    od = OrderedDict()
    od['a'] = pd.DataFrame(df1)
    od['b'] = pd.DataFrame(df1)
    od['c'] = pd.DataFrame(df1)
    od['d'] = pd.DataFrame(df1)

    od2 = OrderedDict()
    od2['a'] = pd.DataFrame(df2)
    od2['b'] = pd.DataFrame(df2)
    od2['c'] = pd.DataFrame(df2)
    od2['d'] = pd.DataFrame(df2)

    test = assert_frame_equal(od, od2)
    print(test)


    I have 2 OrderedDict made of pandas DataFrames and I would like to analyze if the single elements inside the DataFrames are equal.



    I found the function assert_frame_equal that works perfectly when it comes to compare 2 DataFrames, but gives this error with OrderedDict:




    AssertionError: DataFrame Expected type class
    'pandas.core.frame.DataFrame', found class
    'collections.OrderedDict' instead




    Is there any solution or workaround to this? Take into account that I necessarily start from an OrderedDict and unfortunately I cannot change that.



    Thanks so much in advance any help/hint on this issue.










    share|improve this question

























      0












      0








      0








      I am facing a comparing problem, this is my code:



      import pandas as pd
      from collections import OrderedDict
      from pandas.util.testing import assert_frame_equal

      df1 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
      'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
      'three' : pd.Series([1., 2., 3., 4., 5.], index=['a', 'b', 'c', 'd','e'])}

      df2 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
      'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
      'three' : pd.Series([1., 2., 3., 4., 5.], index=['a', 'b', 'c', 'd','e'])}
      od = OrderedDict()
      od['a'] = pd.DataFrame(df1)
      od['b'] = pd.DataFrame(df1)
      od['c'] = pd.DataFrame(df1)
      od['d'] = pd.DataFrame(df1)

      od2 = OrderedDict()
      od2['a'] = pd.DataFrame(df2)
      od2['b'] = pd.DataFrame(df2)
      od2['c'] = pd.DataFrame(df2)
      od2['d'] = pd.DataFrame(df2)

      test = assert_frame_equal(od, od2)
      print(test)


      I have 2 OrderedDict made of pandas DataFrames and I would like to analyze if the single elements inside the DataFrames are equal.



      I found the function assert_frame_equal that works perfectly when it comes to compare 2 DataFrames, but gives this error with OrderedDict:




      AssertionError: DataFrame Expected type class
      'pandas.core.frame.DataFrame', found class
      'collections.OrderedDict' instead




      Is there any solution or workaround to this? Take into account that I necessarily start from an OrderedDict and unfortunately I cannot change that.



      Thanks so much in advance any help/hint on this issue.










      share|improve this question














      I am facing a comparing problem, this is my code:



      import pandas as pd
      from collections import OrderedDict
      from pandas.util.testing import assert_frame_equal

      df1 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
      'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
      'three' : pd.Series([1., 2., 3., 4., 5.], index=['a', 'b', 'c', 'd','e'])}

      df2 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
      'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
      'three' : pd.Series([1., 2., 3., 4., 5.], index=['a', 'b', 'c', 'd','e'])}
      od = OrderedDict()
      od['a'] = pd.DataFrame(df1)
      od['b'] = pd.DataFrame(df1)
      od['c'] = pd.DataFrame(df1)
      od['d'] = pd.DataFrame(df1)

      od2 = OrderedDict()
      od2['a'] = pd.DataFrame(df2)
      od2['b'] = pd.DataFrame(df2)
      od2['c'] = pd.DataFrame(df2)
      od2['d'] = pd.DataFrame(df2)

      test = assert_frame_equal(od, od2)
      print(test)


      I have 2 OrderedDict made of pandas DataFrames and I would like to analyze if the single elements inside the DataFrames are equal.



      I found the function assert_frame_equal that works perfectly when it comes to compare 2 DataFrames, but gives this error with OrderedDict:




      AssertionError: DataFrame Expected type class
      'pandas.core.frame.DataFrame', found class
      'collections.OrderedDict' instead




      Is there any solution or workaround to this? Take into account that I necessarily start from an OrderedDict and unfortunately I cannot change that.



      Thanks so much in advance any help/hint on this issue.







      python-3.x pandas dictionary dataframe compare






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 16:22









      iraciv94iraciv94

      14810




      14810
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Something like this?



          for df1, df2 in zip(od.values(), od2.values()):
          test = assert_frame_equal(df1, df2)
          print(test)


          Returns:



          None
          None
          None
          None


          Also, you are calling your initial OrderedDicts df1, which might lead to some confusion later on. By convention, df is short for DataFrame.



          You can also use equal, per What is the difference between `assert_frame_equal` and `equals`



          for df1, df2 in zip(od.values(), od2.values()):
          test = df1.equals(df2)
          print(test)


          Returns:



          True
          True
          True
          True





          share|improve this answer































            1














            Look if this helps. Using zip()



            for ord1, ord2 in zip(od.values(), od2.values()):

            print(assert_frame_equal(ord1, ord2))

            # or you can also use
            print(ord1.equals(ord2))


            Hope this helps






            share|improve this answer


























            • The values in od and od2 are dataframes, so I don't think the constructor needs to be called. k and v are shorthand for key and value, so using k to refer to od.values() may be confusing for some.

              – Evan
              Nov 15 '18 at 18:35











            • @Evan I agree with you.

              – Srce Cde
              Nov 15 '18 at 18:41











            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%2f53323769%2fcomparing-orderdict-of-dataframes%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









            1














            Something like this?



            for df1, df2 in zip(od.values(), od2.values()):
            test = assert_frame_equal(df1, df2)
            print(test)


            Returns:



            None
            None
            None
            None


            Also, you are calling your initial OrderedDicts df1, which might lead to some confusion later on. By convention, df is short for DataFrame.



            You can also use equal, per What is the difference between `assert_frame_equal` and `equals`



            for df1, df2 in zip(od.values(), od2.values()):
            test = df1.equals(df2)
            print(test)


            Returns:



            True
            True
            True
            True





            share|improve this answer




























              1














              Something like this?



              for df1, df2 in zip(od.values(), od2.values()):
              test = assert_frame_equal(df1, df2)
              print(test)


              Returns:



              None
              None
              None
              None


              Also, you are calling your initial OrderedDicts df1, which might lead to some confusion later on. By convention, df is short for DataFrame.



              You can also use equal, per What is the difference between `assert_frame_equal` and `equals`



              for df1, df2 in zip(od.values(), od2.values()):
              test = df1.equals(df2)
              print(test)


              Returns:



              True
              True
              True
              True





              share|improve this answer


























                1












                1








                1







                Something like this?



                for df1, df2 in zip(od.values(), od2.values()):
                test = assert_frame_equal(df1, df2)
                print(test)


                Returns:



                None
                None
                None
                None


                Also, you are calling your initial OrderedDicts df1, which might lead to some confusion later on. By convention, df is short for DataFrame.



                You can also use equal, per What is the difference between `assert_frame_equal` and `equals`



                for df1, df2 in zip(od.values(), od2.values()):
                test = df1.equals(df2)
                print(test)


                Returns:



                True
                True
                True
                True





                share|improve this answer













                Something like this?



                for df1, df2 in zip(od.values(), od2.values()):
                test = assert_frame_equal(df1, df2)
                print(test)


                Returns:



                None
                None
                None
                None


                Also, you are calling your initial OrderedDicts df1, which might lead to some confusion later on. By convention, df is short for DataFrame.



                You can also use equal, per What is the difference between `assert_frame_equal` and `equals`



                for df1, df2 in zip(od.values(), od2.values()):
                test = df1.equals(df2)
                print(test)


                Returns:



                True
                True
                True
                True






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 18:34









                EvanEvan

                1,141516




                1,141516

























                    1














                    Look if this helps. Using zip()



                    for ord1, ord2 in zip(od.values(), od2.values()):

                    print(assert_frame_equal(ord1, ord2))

                    # or you can also use
                    print(ord1.equals(ord2))


                    Hope this helps






                    share|improve this answer


























                    • The values in od and od2 are dataframes, so I don't think the constructor needs to be called. k and v are shorthand for key and value, so using k to refer to od.values() may be confusing for some.

                      – Evan
                      Nov 15 '18 at 18:35











                    • @Evan I agree with you.

                      – Srce Cde
                      Nov 15 '18 at 18:41
















                    1














                    Look if this helps. Using zip()



                    for ord1, ord2 in zip(od.values(), od2.values()):

                    print(assert_frame_equal(ord1, ord2))

                    # or you can also use
                    print(ord1.equals(ord2))


                    Hope this helps






                    share|improve this answer


























                    • The values in od and od2 are dataframes, so I don't think the constructor needs to be called. k and v are shorthand for key and value, so using k to refer to od.values() may be confusing for some.

                      – Evan
                      Nov 15 '18 at 18:35











                    • @Evan I agree with you.

                      – Srce Cde
                      Nov 15 '18 at 18:41














                    1












                    1








                    1







                    Look if this helps. Using zip()



                    for ord1, ord2 in zip(od.values(), od2.values()):

                    print(assert_frame_equal(ord1, ord2))

                    # or you can also use
                    print(ord1.equals(ord2))


                    Hope this helps






                    share|improve this answer















                    Look if this helps. Using zip()



                    for ord1, ord2 in zip(od.values(), od2.values()):

                    print(assert_frame_equal(ord1, ord2))

                    # or you can also use
                    print(ord1.equals(ord2))


                    Hope this helps







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 29 '18 at 18:16

























                    answered Nov 15 '18 at 18:29









                    Srce CdeSrce Cde

                    1,186512




                    1,186512













                    • The values in od and od2 are dataframes, so I don't think the constructor needs to be called. k and v are shorthand for key and value, so using k to refer to od.values() may be confusing for some.

                      – Evan
                      Nov 15 '18 at 18:35











                    • @Evan I agree with you.

                      – Srce Cde
                      Nov 15 '18 at 18:41



















                    • The values in od and od2 are dataframes, so I don't think the constructor needs to be called. k and v are shorthand for key and value, so using k to refer to od.values() may be confusing for some.

                      – Evan
                      Nov 15 '18 at 18:35











                    • @Evan I agree with you.

                      – Srce Cde
                      Nov 15 '18 at 18:41

















                    The values in od and od2 are dataframes, so I don't think the constructor needs to be called. k and v are shorthand for key and value, so using k to refer to od.values() may be confusing for some.

                    – Evan
                    Nov 15 '18 at 18:35





                    The values in od and od2 are dataframes, so I don't think the constructor needs to be called. k and v are shorthand for key and value, so using k to refer to od.values() may be confusing for some.

                    – Evan
                    Nov 15 '18 at 18:35













                    @Evan I agree with you.

                    – Srce Cde
                    Nov 15 '18 at 18:41





                    @Evan I agree with you.

                    – Srce Cde
                    Nov 15 '18 at 18:41


















                    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%2f53323769%2fcomparing-orderdict-of-dataframes%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

                    Bressuire

                    Vorschmack

                    Quarantine