Get header in genfromtxt when using skip_header











up vote
-1
down vote

favorite












I have data I want to plot and analyse, looking like:



0101 
1 3
2 4
3 6


I use skip_header in genfromtxt to load the file 2 column data, however I also need the header for reference.



Is there a way to get the header back?










share|improve this question
























  • Use a regular Python file read to get that line,
    – hpaulj
    11 hours ago










  • For genfrontxt this isn't a valid column header. So are right to skip it. And there's no provision for saving or recording skipped lines. Why should there be?
    – hpaulj
    5 hours ago















up vote
-1
down vote

favorite












I have data I want to plot and analyse, looking like:



0101 
1 3
2 4
3 6


I use skip_header in genfromtxt to load the file 2 column data, however I also need the header for reference.



Is there a way to get the header back?










share|improve this question
























  • Use a regular Python file read to get that line,
    – hpaulj
    11 hours ago










  • For genfrontxt this isn't a valid column header. So are right to skip it. And there's no provision for saving or recording skipped lines. Why should there be?
    – hpaulj
    5 hours ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have data I want to plot and analyse, looking like:



0101 
1 3
2 4
3 6


I use skip_header in genfromtxt to load the file 2 column data, however I also need the header for reference.



Is there a way to get the header back?










share|improve this question















I have data I want to plot and analyse, looking like:



0101 
1 3
2 4
3 6


I use skip_header in genfromtxt to load the file 2 column data, however I also need the header for reference.



Is there a way to get the header back?







python numpy genfromtxt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 11 hours ago









hpaulj

107k673137




107k673137










asked 12 hours ago









StarStrides

5119




5119












  • Use a regular Python file read to get that line,
    – hpaulj
    11 hours ago










  • For genfrontxt this isn't a valid column header. So are right to skip it. And there's no provision for saving or recording skipped lines. Why should there be?
    – hpaulj
    5 hours ago


















  • Use a regular Python file read to get that line,
    – hpaulj
    11 hours ago










  • For genfrontxt this isn't a valid column header. So are right to skip it. And there's no provision for saving or recording skipped lines. Why should there be?
    – hpaulj
    5 hours ago
















Use a regular Python file read to get that line,
– hpaulj
11 hours ago




Use a regular Python file read to get that line,
– hpaulj
11 hours ago












For genfrontxt this isn't a valid column header. So are right to skip it. And there's no provision for saving or recording skipped lines. Why should there be?
– hpaulj
5 hours ago




For genfrontxt this isn't a valid column header. So are right to skip it. And there's no provision for saving or recording skipped lines. Why should there be?
– hpaulj
5 hours ago












2 Answers
2






active

oldest

votes

















up vote
0
down vote













I am not sure that this is implemented in numpy.genfromtxt(). You may have to call the function twice, once for the header, and a second time for the data. Or you may want to have a look at the functions offered by pandas, such as read_table.






share|improve this answer








New contributor




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

























    up vote
    0
    down vote













    You can try with pd.read_csv:



    data = pd.read_csv(filename, sep=" ")


    So that the first line is read as header






    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',
      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%2f53371876%2fget-header-in-genfromtxt-when-using-skip-header%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








      up vote
      0
      down vote













      I am not sure that this is implemented in numpy.genfromtxt(). You may have to call the function twice, once for the header, and a second time for the data. Or you may want to have a look at the functions offered by pandas, such as read_table.






      share|improve this answer








      New contributor




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






















        up vote
        0
        down vote













        I am not sure that this is implemented in numpy.genfromtxt(). You may have to call the function twice, once for the header, and a second time for the data. Or you may want to have a look at the functions offered by pandas, such as read_table.






        share|improve this answer








        New contributor




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




















          up vote
          0
          down vote










          up vote
          0
          down vote









          I am not sure that this is implemented in numpy.genfromtxt(). You may have to call the function twice, once for the header, and a second time for the data. Or you may want to have a look at the functions offered by pandas, such as read_table.






          share|improve this answer








          New contributor




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









          I am not sure that this is implemented in numpy.genfromtxt(). You may have to call the function twice, once for the header, and a second time for the data. Or you may want to have a look at the functions offered by pandas, such as read_table.







          share|improve this answer








          New contributor




          Patol75 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 answer



          share|improve this answer






          New contributor




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









          answered 12 hours ago









          Patol75

          4636




          4636




          New contributor




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





          New contributor





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






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
























              up vote
              0
              down vote













              You can try with pd.read_csv:



              data = pd.read_csv(filename, sep=" ")


              So that the first line is read as header






              share|improve this answer



























                up vote
                0
                down vote













                You can try with pd.read_csv:



                data = pd.read_csv(filename, sep=" ")


                So that the first line is read as header






                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You can try with pd.read_csv:



                  data = pd.read_csv(filename, sep=" ")


                  So that the first line is read as header






                  share|improve this answer














                  You can try with pd.read_csv:



                  data = pd.read_csv(filename, sep=" ")


                  So that the first line is read as header







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 11 hours ago

























                  answered 12 hours ago









                  Joe

                  5,36221127




                  5,36221127






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371876%2fget-header-in-genfromtxt-when-using-skip-header%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

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      SQL update select statement

                      'app-layout' is not a known element: how to share Component with different Modules