Concatenate pandas Data frame with Series and multiply the second element












0















I have a pandas data frame with many rows and columns like this



Name        Skill       Age
Adam C++ 23
Beth Java 25
Micheal Scala 21
...
Aaron Erlang 23


I have another list from which i can create a pandas series



dept = ['Country', 'UK']
pd.Series[dept]
s = pd.Series(dept)


Now i want to concat the dataframe and the Series with Second element of the list should be repeated.



Name        Skill       Age         Country
Adam C++ 23 UK
Beth Java 25 UK
Micheal Scala 21 UK
...
Aaron Erlang 23 UK


UK should be repeated and the Country should become the label for the series.



I am clueless on how to achieve this










share|improve this question


















  • 1





    what about this df['Country']='UK' without a series

    – Mohamed Thasin ah
    Jan 2 at 9:33













  • @MohamedThasinah exactly. @jhon.smith no need for series

    – meW
    Jan 2 at 9:34













  • Possible duplicate of Set value to an entire column of a pandas dataframe

    – anky_91
    Jan 2 at 9:43











  • Hey Mohamed Thanks that's brilliant i was stupid not to think of an simple and elegant solution

    – jhon.smith
    Jan 4 at 13:25
















0















I have a pandas data frame with many rows and columns like this



Name        Skill       Age
Adam C++ 23
Beth Java 25
Micheal Scala 21
...
Aaron Erlang 23


I have another list from which i can create a pandas series



dept = ['Country', 'UK']
pd.Series[dept]
s = pd.Series(dept)


Now i want to concat the dataframe and the Series with Second element of the list should be repeated.



Name        Skill       Age         Country
Adam C++ 23 UK
Beth Java 25 UK
Micheal Scala 21 UK
...
Aaron Erlang 23 UK


UK should be repeated and the Country should become the label for the series.



I am clueless on how to achieve this










share|improve this question


















  • 1





    what about this df['Country']='UK' without a series

    – Mohamed Thasin ah
    Jan 2 at 9:33













  • @MohamedThasinah exactly. @jhon.smith no need for series

    – meW
    Jan 2 at 9:34













  • Possible duplicate of Set value to an entire column of a pandas dataframe

    – anky_91
    Jan 2 at 9:43











  • Hey Mohamed Thanks that's brilliant i was stupid not to think of an simple and elegant solution

    – jhon.smith
    Jan 4 at 13:25














0












0








0








I have a pandas data frame with many rows and columns like this



Name        Skill       Age
Adam C++ 23
Beth Java 25
Micheal Scala 21
...
Aaron Erlang 23


I have another list from which i can create a pandas series



dept = ['Country', 'UK']
pd.Series[dept]
s = pd.Series(dept)


Now i want to concat the dataframe and the Series with Second element of the list should be repeated.



Name        Skill       Age         Country
Adam C++ 23 UK
Beth Java 25 UK
Micheal Scala 21 UK
...
Aaron Erlang 23 UK


UK should be repeated and the Country should become the label for the series.



I am clueless on how to achieve this










share|improve this question














I have a pandas data frame with many rows and columns like this



Name        Skill       Age
Adam C++ 23
Beth Java 25
Micheal Scala 21
...
Aaron Erlang 23


I have another list from which i can create a pandas series



dept = ['Country', 'UK']
pd.Series[dept]
s = pd.Series(dept)


Now i want to concat the dataframe and the Series with Second element of the list should be repeated.



Name        Skill       Age         Country
Adam C++ 23 UK
Beth Java 25 UK
Micheal Scala 21 UK
...
Aaron Erlang 23 UK


UK should be repeated and the Country should become the label for the series.



I am clueless on how to achieve this







python-3.x pandas






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 9:32









jhon.smithjhon.smith

79741534




79741534








  • 1





    what about this df['Country']='UK' without a series

    – Mohamed Thasin ah
    Jan 2 at 9:33













  • @MohamedThasinah exactly. @jhon.smith no need for series

    – meW
    Jan 2 at 9:34













  • Possible duplicate of Set value to an entire column of a pandas dataframe

    – anky_91
    Jan 2 at 9:43











  • Hey Mohamed Thanks that's brilliant i was stupid not to think of an simple and elegant solution

    – jhon.smith
    Jan 4 at 13:25














  • 1





    what about this df['Country']='UK' without a series

    – Mohamed Thasin ah
    Jan 2 at 9:33













  • @MohamedThasinah exactly. @jhon.smith no need for series

    – meW
    Jan 2 at 9:34













  • Possible duplicate of Set value to an entire column of a pandas dataframe

    – anky_91
    Jan 2 at 9:43











  • Hey Mohamed Thanks that's brilliant i was stupid not to think of an simple and elegant solution

    – jhon.smith
    Jan 4 at 13:25








1




1





what about this df['Country']='UK' without a series

– Mohamed Thasin ah
Jan 2 at 9:33







what about this df['Country']='UK' without a series

– Mohamed Thasin ah
Jan 2 at 9:33















@MohamedThasinah exactly. @jhon.smith no need for series

– meW
Jan 2 at 9:34







@MohamedThasinah exactly. @jhon.smith no need for series

– meW
Jan 2 at 9:34















Possible duplicate of Set value to an entire column of a pandas dataframe

– anky_91
Jan 2 at 9:43





Possible duplicate of Set value to an entire column of a pandas dataframe

– anky_91
Jan 2 at 9:43













Hey Mohamed Thanks that's brilliant i was stupid not to think of an simple and elegant solution

– jhon.smith
Jan 4 at 13:25





Hey Mohamed Thanks that's brilliant i was stupid not to think of an simple and elegant solution

– jhon.smith
Jan 4 at 13:25












1 Answer
1






active

oldest

votes


















1














Select values of list by indexing for column name and for values:



dept = ['Country', 'UK']

df[dept[0]] = dept[1]
print (df)
Name Skill Age Country
0 Adam C++ 23 UK
1 Beth Java 25 UK
2 Micheal Scala 21 UK
3 Aaron Erlang 23 UK


If input data is Series select by position by Series.iat:



s = pd.Series(dept)
df[s.iat[0]] = s.iat[1]
#if default RangeIndex
#df[s[0]] = s[1]





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%2f54003974%2fconcatenate-pandas-data-frame-with-series-and-multiply-the-second-element%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Select values of list by indexing for column name and for values:



    dept = ['Country', 'UK']

    df[dept[0]] = dept[1]
    print (df)
    Name Skill Age Country
    0 Adam C++ 23 UK
    1 Beth Java 25 UK
    2 Micheal Scala 21 UK
    3 Aaron Erlang 23 UK


    If input data is Series select by position by Series.iat:



    s = pd.Series(dept)
    df[s.iat[0]] = s.iat[1]
    #if default RangeIndex
    #df[s[0]] = s[1]





    share|improve this answer






























      1














      Select values of list by indexing for column name and for values:



      dept = ['Country', 'UK']

      df[dept[0]] = dept[1]
      print (df)
      Name Skill Age Country
      0 Adam C++ 23 UK
      1 Beth Java 25 UK
      2 Micheal Scala 21 UK
      3 Aaron Erlang 23 UK


      If input data is Series select by position by Series.iat:



      s = pd.Series(dept)
      df[s.iat[0]] = s.iat[1]
      #if default RangeIndex
      #df[s[0]] = s[1]





      share|improve this answer




























        1












        1








        1







        Select values of list by indexing for column name and for values:



        dept = ['Country', 'UK']

        df[dept[0]] = dept[1]
        print (df)
        Name Skill Age Country
        0 Adam C++ 23 UK
        1 Beth Java 25 UK
        2 Micheal Scala 21 UK
        3 Aaron Erlang 23 UK


        If input data is Series select by position by Series.iat:



        s = pd.Series(dept)
        df[s.iat[0]] = s.iat[1]
        #if default RangeIndex
        #df[s[0]] = s[1]





        share|improve this answer















        Select values of list by indexing for column name and for values:



        dept = ['Country', 'UK']

        df[dept[0]] = dept[1]
        print (df)
        Name Skill Age Country
        0 Adam C++ 23 UK
        1 Beth Java 25 UK
        2 Micheal Scala 21 UK
        3 Aaron Erlang 23 UK


        If input data is Series select by position by Series.iat:



        s = pd.Series(dept)
        df[s.iat[0]] = s.iat[1]
        #if default RangeIndex
        #df[s[0]] = s[1]






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 2 at 9:42

























        answered Jan 2 at 9:36









        jezraeljezrael

        345k25300371




        345k25300371
































            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%2f54003974%2fconcatenate-pandas-data-frame-with-series-and-multiply-the-second-element%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

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas