how to replace multiple column in one column in txt file





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







0















I have a txt file file1.csv with 6 column. They are ordered like this:



$ cat file1.csv (tab delimited)(752 rows)
1 1011001 1001164 981328 1 -9
1 1011002 1001164 981328 1 -9
1 1011003 1001085 981149 1 -9


and



$ cat file2.txt (space delimited and it's a large file with 52872 column and 752 row)



1011001 CC GG TT AA ...
1011003 GG TT AA CC ...
1011002 TT GG CC AA ...


How can I replace of first column in file2.txt with all of 6 column in file1.csv as follow:



1   1011001 1001164 981328  1   -9  C   C   G   G   T   T   T   A   A   ...
1 1011002 1001164 981328 1 -9 T T G G C C A A
1 1011003 1001085 981149 1 -9 G G T T A A C C









share|improve this question

























  • You mean like , 1 1011001 1001164 981328 1 -9 CC GG TT AA ... right? or one of your example in the question is not right?

    – Haramoz
    Jan 3 at 4:23











  • I have two as : file1.cvs and file2.txt . i want to make 3th file. in file 3, the genotype should be seperated and 6 columns in first file replace at first column on the second file.I mean yse just genotype sholud be seperated

    – mary
    Jan 3 at 5:28




















0















I have a txt file file1.csv with 6 column. They are ordered like this:



$ cat file1.csv (tab delimited)(752 rows)
1 1011001 1001164 981328 1 -9
1 1011002 1001164 981328 1 -9
1 1011003 1001085 981149 1 -9


and



$ cat file2.txt (space delimited and it's a large file with 52872 column and 752 row)



1011001 CC GG TT AA ...
1011003 GG TT AA CC ...
1011002 TT GG CC AA ...


How can I replace of first column in file2.txt with all of 6 column in file1.csv as follow:



1   1011001 1001164 981328  1   -9  C   C   G   G   T   T   T   A   A   ...
1 1011002 1001164 981328 1 -9 T T G G C C A A
1 1011003 1001085 981149 1 -9 G G T T A A C C









share|improve this question

























  • You mean like , 1 1011001 1001164 981328 1 -9 CC GG TT AA ... right? or one of your example in the question is not right?

    – Haramoz
    Jan 3 at 4:23











  • I have two as : file1.cvs and file2.txt . i want to make 3th file. in file 3, the genotype should be seperated and 6 columns in first file replace at first column on the second file.I mean yse just genotype sholud be seperated

    – mary
    Jan 3 at 5:28
















0












0








0


1






I have a txt file file1.csv with 6 column. They are ordered like this:



$ cat file1.csv (tab delimited)(752 rows)
1 1011001 1001164 981328 1 -9
1 1011002 1001164 981328 1 -9
1 1011003 1001085 981149 1 -9


and



$ cat file2.txt (space delimited and it's a large file with 52872 column and 752 row)



1011001 CC GG TT AA ...
1011003 GG TT AA CC ...
1011002 TT GG CC AA ...


How can I replace of first column in file2.txt with all of 6 column in file1.csv as follow:



1   1011001 1001164 981328  1   -9  C   C   G   G   T   T   T   A   A   ...
1 1011002 1001164 981328 1 -9 T T G G C C A A
1 1011003 1001085 981149 1 -9 G G T T A A C C









share|improve this question
















I have a txt file file1.csv with 6 column. They are ordered like this:



$ cat file1.csv (tab delimited)(752 rows)
1 1011001 1001164 981328 1 -9
1 1011002 1001164 981328 1 -9
1 1011003 1001085 981149 1 -9


and



$ cat file2.txt (space delimited and it's a large file with 52872 column and 752 row)



1011001 CC GG TT AA ...
1011003 GG TT AA CC ...
1011002 TT GG CC AA ...


How can I replace of first column in file2.txt with all of 6 column in file1.csv as follow:



1   1011001 1001164 981328  1   -9  C   C   G   G   T   T   T   A   A   ...
1 1011002 1001164 981328 1 -9 T T G G C C A A
1 1011003 1001085 981149 1 -9 G G T T A A C C






python pandas python-2.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 6:49









Haramoz

458418




458418










asked Jan 3 at 4:17









marymary

244




244













  • You mean like , 1 1011001 1001164 981328 1 -9 CC GG TT AA ... right? or one of your example in the question is not right?

    – Haramoz
    Jan 3 at 4:23











  • I have two as : file1.cvs and file2.txt . i want to make 3th file. in file 3, the genotype should be seperated and 6 columns in first file replace at first column on the second file.I mean yse just genotype sholud be seperated

    – mary
    Jan 3 at 5:28





















  • You mean like , 1 1011001 1001164 981328 1 -9 CC GG TT AA ... right? or one of your example in the question is not right?

    – Haramoz
    Jan 3 at 4:23











  • I have two as : file1.cvs and file2.txt . i want to make 3th file. in file 3, the genotype should be seperated and 6 columns in first file replace at first column on the second file.I mean yse just genotype sholud be seperated

    – mary
    Jan 3 at 5:28



















You mean like , 1 1011001 1001164 981328 1 -9 CC GG TT AA ... right? or one of your example in the question is not right?

– Haramoz
Jan 3 at 4:23





You mean like , 1 1011001 1001164 981328 1 -9 CC GG TT AA ... right? or one of your example in the question is not right?

– Haramoz
Jan 3 at 4:23













I have two as : file1.cvs and file2.txt . i want to make 3th file. in file 3, the genotype should be seperated and 6 columns in first file replace at first column on the second file.I mean yse just genotype sholud be seperated

– mary
Jan 3 at 5:28







I have two as : file1.cvs and file2.txt . i want to make 3th file. in file 3, the genotype should be seperated and 6 columns in first file replace at first column on the second file.I mean yse just genotype sholud be seperated

– mary
Jan 3 at 5:28














2 Answers
2






active

oldest

votes


















1














import pandas as pd

file_1=pd.read_csv('file1.csv', header=None)
file_2=pd.read_csv('file2.txt', sep=' ')

combined_df = file_1.join(file_2, left_on=1, right_index=True)


Faisel makes a good point below. You likely want to save the newly combined data to an output.






share|improve this answer































    0














    I would recommend looking into Pandas package for easy manipulations of .csv file. In you case:



    import pandas as pd

    df1 = pd.read_csv('file1.txt')
    df2 = pd.read_csv('file2.txt')

    df = pd.pd.concat([df1, df2], axix=1)

    # Optionally save it back to csv file
    df.to_csv('final.txt')





    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%2f54016276%2fhow-to-replace-multiple-column-in-one-column-in-txt-file%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














      import pandas as pd

      file_1=pd.read_csv('file1.csv', header=None)
      file_2=pd.read_csv('file2.txt', sep=' ')

      combined_df = file_1.join(file_2, left_on=1, right_index=True)


      Faisel makes a good point below. You likely want to save the newly combined data to an output.






      share|improve this answer




























        1














        import pandas as pd

        file_1=pd.read_csv('file1.csv', header=None)
        file_2=pd.read_csv('file2.txt', sep=' ')

        combined_df = file_1.join(file_2, left_on=1, right_index=True)


        Faisel makes a good point below. You likely want to save the newly combined data to an output.






        share|improve this answer


























          1












          1








          1







          import pandas as pd

          file_1=pd.read_csv('file1.csv', header=None)
          file_2=pd.read_csv('file2.txt', sep=' ')

          combined_df = file_1.join(file_2, left_on=1, right_index=True)


          Faisel makes a good point below. You likely want to save the newly combined data to an output.






          share|improve this answer













          import pandas as pd

          file_1=pd.read_csv('file1.csv', header=None)
          file_2=pd.read_csv('file2.txt', sep=' ')

          combined_df = file_1.join(file_2, left_on=1, right_index=True)


          Faisel makes a good point below. You likely want to save the newly combined data to an output.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 4:29









          omadisonomadison

          328




          328

























              0














              I would recommend looking into Pandas package for easy manipulations of .csv file. In you case:



              import pandas as pd

              df1 = pd.read_csv('file1.txt')
              df2 = pd.read_csv('file2.txt')

              df = pd.pd.concat([df1, df2], axix=1)

              # Optionally save it back to csv file
              df.to_csv('final.txt')





              share|improve this answer




























                0














                I would recommend looking into Pandas package for easy manipulations of .csv file. In you case:



                import pandas as pd

                df1 = pd.read_csv('file1.txt')
                df2 = pd.read_csv('file2.txt')

                df = pd.pd.concat([df1, df2], axix=1)

                # Optionally save it back to csv file
                df.to_csv('final.txt')





                share|improve this answer


























                  0












                  0








                  0







                  I would recommend looking into Pandas package for easy manipulations of .csv file. In you case:



                  import pandas as pd

                  df1 = pd.read_csv('file1.txt')
                  df2 = pd.read_csv('file2.txt')

                  df = pd.pd.concat([df1, df2], axix=1)

                  # Optionally save it back to csv file
                  df.to_csv('final.txt')





                  share|improve this answer













                  I would recommend looking into Pandas package for easy manipulations of .csv file. In you case:



                  import pandas as pd

                  df1 = pd.read_csv('file1.txt')
                  df2 = pd.read_csv('file2.txt')

                  df = pd.pd.concat([df1, df2], axix=1)

                  # Optionally save it back to csv file
                  df.to_csv('final.txt')






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 3 at 4:30









                  faisalfaisal

                  1836




                  1836






























                      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%2f54016276%2fhow-to-replace-multiple-column-in-one-column-in-txt-file%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

                      Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                      Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                      A Topological Invariant for $pi_3(U(n))$