What's the difference between df.head() and df.head?












-1















In Jupyter Notebook or terminal, both df.head and df.head() can return an output of the dataframe, with some minor differences. What's the fundamental difference between the two different expressions and what role does parenthesis play in Python in general?
Thanks!



>>>df.head
<bound method NDFrame.head of Date Open High Low Close Volume
0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
4 7-Jun-17 155.02 155.98 154.48 155.37 21069647
5 8-Jun-17 155.25 155.54 154.40 154.99 21250798
6 9-Jun-17 155.19 155.19 146.02 148.98 64882657
7 12-Jun-17 145.74 146.09 142.51 145.42 72307330
8 13-Jun-17 147.16 147.45 145.15 146.59 34165445
9 14-Jun-17 147.50 147.50 143.84 145.16 31531232
10 15-Jun-17 143.32 144.48 142.21 144.29 32165373
>>> df.head()
Date Open High Low Close Volume
0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
4 7-Jun-17 155.02 155.98 154.48 155.37 21069647









share|improve this question





























    -1















    In Jupyter Notebook or terminal, both df.head and df.head() can return an output of the dataframe, with some minor differences. What's the fundamental difference between the two different expressions and what role does parenthesis play in Python in general?
    Thanks!



    >>>df.head
    <bound method NDFrame.head of Date Open High Low Close Volume
    0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
    1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
    2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
    3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
    4 7-Jun-17 155.02 155.98 154.48 155.37 21069647
    5 8-Jun-17 155.25 155.54 154.40 154.99 21250798
    6 9-Jun-17 155.19 155.19 146.02 148.98 64882657
    7 12-Jun-17 145.74 146.09 142.51 145.42 72307330
    8 13-Jun-17 147.16 147.45 145.15 146.59 34165445
    9 14-Jun-17 147.50 147.50 143.84 145.16 31531232
    10 15-Jun-17 143.32 144.48 142.21 144.29 32165373
    >>> df.head()
    Date Open High Low Close Volume
    0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
    1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
    2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
    3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
    4 7-Jun-17 155.02 155.98 154.48 155.37 21069647









    share|improve this question



























      -1












      -1








      -1








      In Jupyter Notebook or terminal, both df.head and df.head() can return an output of the dataframe, with some minor differences. What's the fundamental difference between the two different expressions and what role does parenthesis play in Python in general?
      Thanks!



      >>>df.head
      <bound method NDFrame.head of Date Open High Low Close Volume
      0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
      1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
      2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
      3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
      4 7-Jun-17 155.02 155.98 154.48 155.37 21069647
      5 8-Jun-17 155.25 155.54 154.40 154.99 21250798
      6 9-Jun-17 155.19 155.19 146.02 148.98 64882657
      7 12-Jun-17 145.74 146.09 142.51 145.42 72307330
      8 13-Jun-17 147.16 147.45 145.15 146.59 34165445
      9 14-Jun-17 147.50 147.50 143.84 145.16 31531232
      10 15-Jun-17 143.32 144.48 142.21 144.29 32165373
      >>> df.head()
      Date Open High Low Close Volume
      0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
      1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
      2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
      3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
      4 7-Jun-17 155.02 155.98 154.48 155.37 21069647









      share|improve this question
















      In Jupyter Notebook or terminal, both df.head and df.head() can return an output of the dataframe, with some minor differences. What's the fundamental difference between the two different expressions and what role does parenthesis play in Python in general?
      Thanks!



      >>>df.head
      <bound method NDFrame.head of Date Open High Low Close Volume
      0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
      1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
      2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
      3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
      4 7-Jun-17 155.02 155.98 154.48 155.37 21069647
      5 8-Jun-17 155.25 155.54 154.40 154.99 21250798
      6 9-Jun-17 155.19 155.19 146.02 148.98 64882657
      7 12-Jun-17 145.74 146.09 142.51 145.42 72307330
      8 13-Jun-17 147.16 147.45 145.15 146.59 34165445
      9 14-Jun-17 147.50 147.50 143.84 145.16 31531232
      10 15-Jun-17 143.32 144.48 142.21 144.29 32165373
      >>> df.head()
      Date Open High Low Close Volume
      0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
      1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
      2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
      3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
      4 7-Jun-17 155.02 155.98 154.48 155.37 21069647






      python python-3.x pandas jupyter-notebook






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 22:03









      Paul Rooney

      12.7k72845




      12.7k72845










      asked Jan 1 at 22:02









      Jason HuJason Hu

      12




      12
























          3 Answers
          3






          active

          oldest

          votes


















          5














          Those aren't just "minor differences". You didn't actually take the head at all with df.head.



          df.head() actually takes the head of the dataframe. You can see that the output only has 5 rows:



          >>> df.head()
          Date Open High Low Close Volume
          0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
          1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
          2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
          3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
          4 7-Jun-17 155.02 155.98 154.48 155.37 21069647


          In contrast, df.head is just a method object for the head method of the dataframe df. The parentheses are needed to actually call the method. The method object's repr is basically



          f"<bound method {classname}.{methodname} of {object!r}"


          with the class name, method name, and repr of the object substituted in the appropriate places. The part of the output that looks like a dataframe is, in fact, the repr of the original df. It has 10 rows instead of 5 because it's the whole original dataframe, not the head.






          share|improve this answer































            0














            head return a method head() return the top 5(default) row in your dataframe



            type(df.head)
            <class 'method'>
            type(df.head())
            <class 'pandas.core.frame.DataFrame'>





            share|improve this answer































              0














              Parentheses are used to call a function. Let’s take a small example with append just using it without parenthesis on a list will do nothing as it will just return the function itself but using the parenthesis call the function:



              a = [1]
              a.append
              print(a)
              [1]

              a.append(2)
              print(a)
              [1, 2]

              append = a.append
              append(3)
              print(a)
              [1, 2, 3]


              What you see when just using head is similar. They just added some code to actually call the function with default value.






              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%2f53999279%2fwhats-the-difference-between-df-head-and-df-head%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









                5














                Those aren't just "minor differences". You didn't actually take the head at all with df.head.



                df.head() actually takes the head of the dataframe. You can see that the output only has 5 rows:



                >>> df.head()
                Date Open High Low Close Volume
                0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
                1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
                2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
                3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
                4 7-Jun-17 155.02 155.98 154.48 155.37 21069647


                In contrast, df.head is just a method object for the head method of the dataframe df. The parentheses are needed to actually call the method. The method object's repr is basically



                f"<bound method {classname}.{methodname} of {object!r}"


                with the class name, method name, and repr of the object substituted in the appropriate places. The part of the output that looks like a dataframe is, in fact, the repr of the original df. It has 10 rows instead of 5 because it's the whole original dataframe, not the head.






                share|improve this answer




























                  5














                  Those aren't just "minor differences". You didn't actually take the head at all with df.head.



                  df.head() actually takes the head of the dataframe. You can see that the output only has 5 rows:



                  >>> df.head()
                  Date Open High Low Close Volume
                  0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
                  1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
                  2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
                  3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
                  4 7-Jun-17 155.02 155.98 154.48 155.37 21069647


                  In contrast, df.head is just a method object for the head method of the dataframe df. The parentheses are needed to actually call the method. The method object's repr is basically



                  f"<bound method {classname}.{methodname} of {object!r}"


                  with the class name, method name, and repr of the object substituted in the appropriate places. The part of the output that looks like a dataframe is, in fact, the repr of the original df. It has 10 rows instead of 5 because it's the whole original dataframe, not the head.






                  share|improve this answer


























                    5












                    5








                    5







                    Those aren't just "minor differences". You didn't actually take the head at all with df.head.



                    df.head() actually takes the head of the dataframe. You can see that the output only has 5 rows:



                    >>> df.head()
                    Date Open High Low Close Volume
                    0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
                    1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
                    2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
                    3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
                    4 7-Jun-17 155.02 155.98 154.48 155.37 21069647


                    In contrast, df.head is just a method object for the head method of the dataframe df. The parentheses are needed to actually call the method. The method object's repr is basically



                    f"<bound method {classname}.{methodname} of {object!r}"


                    with the class name, method name, and repr of the object substituted in the appropriate places. The part of the output that looks like a dataframe is, in fact, the repr of the original df. It has 10 rows instead of 5 because it's the whole original dataframe, not the head.






                    share|improve this answer













                    Those aren't just "minor differences". You didn't actually take the head at all with df.head.



                    df.head() actually takes the head of the dataframe. You can see that the output only has 5 rows:



                    >>> df.head()
                    Date Open High Low Close Volume
                    0 1-Jun-17 153.17 153.33 152.22 153.18 16404088
                    1 2-Jun-17 153.58 155.45 152.89 155.45 27770715
                    2 5-Jun-17 154.34 154.45 153.46 153.93 25331662
                    3 6-Jun-17 153.90 155.81 153.78 154.45 26624926
                    4 7-Jun-17 155.02 155.98 154.48 155.37 21069647


                    In contrast, df.head is just a method object for the head method of the dataframe df. The parentheses are needed to actually call the method. The method object's repr is basically



                    f"<bound method {classname}.{methodname} of {object!r}"


                    with the class name, method name, and repr of the object substituted in the appropriate places. The part of the output that looks like a dataframe is, in fact, the repr of the original df. It has 10 rows instead of 5 because it's the whole original dataframe, not the head.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 1 at 22:10









                    user2357112user2357112

                    156k12170264




                    156k12170264

























                        0














                        head return a method head() return the top 5(default) row in your dataframe



                        type(df.head)
                        <class 'method'>
                        type(df.head())
                        <class 'pandas.core.frame.DataFrame'>





                        share|improve this answer




























                          0














                          head return a method head() return the top 5(default) row in your dataframe



                          type(df.head)
                          <class 'method'>
                          type(df.head())
                          <class 'pandas.core.frame.DataFrame'>





                          share|improve this answer


























                            0












                            0








                            0







                            head return a method head() return the top 5(default) row in your dataframe



                            type(df.head)
                            <class 'method'>
                            type(df.head())
                            <class 'pandas.core.frame.DataFrame'>





                            share|improve this answer













                            head return a method head() return the top 5(default) row in your dataframe



                            type(df.head)
                            <class 'method'>
                            type(df.head())
                            <class 'pandas.core.frame.DataFrame'>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 1 at 22:10









                            Wen-BenWen-Ben

                            117k83369




                            117k83369























                                0














                                Parentheses are used to call a function. Let’s take a small example with append just using it without parenthesis on a list will do nothing as it will just return the function itself but using the parenthesis call the function:



                                a = [1]
                                a.append
                                print(a)
                                [1]

                                a.append(2)
                                print(a)
                                [1, 2]

                                append = a.append
                                append(3)
                                print(a)
                                [1, 2, 3]


                                What you see when just using head is similar. They just added some code to actually call the function with default value.






                                share|improve this answer






























                                  0














                                  Parentheses are used to call a function. Let’s take a small example with append just using it without parenthesis on a list will do nothing as it will just return the function itself but using the parenthesis call the function:



                                  a = [1]
                                  a.append
                                  print(a)
                                  [1]

                                  a.append(2)
                                  print(a)
                                  [1, 2]

                                  append = a.append
                                  append(3)
                                  print(a)
                                  [1, 2, 3]


                                  What you see when just using head is similar. They just added some code to actually call the function with default value.






                                  share|improve this answer




























                                    0












                                    0








                                    0







                                    Parentheses are used to call a function. Let’s take a small example with append just using it without parenthesis on a list will do nothing as it will just return the function itself but using the parenthesis call the function:



                                    a = [1]
                                    a.append
                                    print(a)
                                    [1]

                                    a.append(2)
                                    print(a)
                                    [1, 2]

                                    append = a.append
                                    append(3)
                                    print(a)
                                    [1, 2, 3]


                                    What you see when just using head is similar. They just added some code to actually call the function with default value.






                                    share|improve this answer















                                    Parentheses are used to call a function. Let’s take a small example with append just using it without parenthesis on a list will do nothing as it will just return the function itself but using the parenthesis call the function:



                                    a = [1]
                                    a.append
                                    print(a)
                                    [1]

                                    a.append(2)
                                    print(a)
                                    [1, 2]

                                    append = a.append
                                    append(3)
                                    print(a)
                                    [1, 2, 3]


                                    What you see when just using head is similar. They just added some code to actually call the function with default value.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jan 1 at 22:18

























                                    answered Jan 1 at 22:03









                                    Y0daY0da

                                    2,12411231




                                    2,12411231






























                                        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%2f53999279%2fwhats-the-difference-between-df-head-and-df-head%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

                                        MongoDB - Not Authorized To Execute Command

                                        How to fix TextFormField cause rebuild widget in Flutter

                                        in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith