How to join/merge/concat an filled datafame with an empty dataframe by index and columns? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to merge two dictionaries in a single expression?How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)Selecting multiple columns in a pandas dataframeAdding new column to existing DataFrame in Python pandasHow to change the order of DataFrame columns?Delete column from pandas DataFrame by column name“Large data” work flows using pandasGet list from pandas DataFrame column headersHow to merge/join/concat dataframes on index in pandas

Why not use the yoke to control yaw, as well as pitch and roll?

Baking rewards as operations

Statistical analysis applied to methods coming out of Machine Learning

How to resize main filesystem

Is this Half-dragon Quaggoth boss monster balanced?

Does the universe have a fixed centre of mass?

Did pre-Columbian Americans know the spherical shape of the Earth?

By what mechanism was the 2017 UK General Election called?

What is the proper term for etching or digging of wall to hide conduit of cables

Is this Kuo-toa homebrew race balanced?

Weaponising the Grasp-at-a-Distance spell

How do I say "this must not happen"?

NIntegrate on a solution of a matrix ODE

2018 MacBook Pro won't let me install macOS High Sierra 10.13 from USB installer

What is a more techy Technical Writer job title that isn't cutesy or confusing?

The test team as an enemy of development? And how can this be avoided?

Twin's vs. Twins'

Why is there so little support for joining EFTA in the British parliament?

New Order #6: Easter Egg

Is it OK to use the testing sample to compare algorithms?

Is the Mordenkainen's Sword spell underpowered?

.bashrc alias for a command with fixed second parameter

Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?

Any stored/leased 737s that could substitute for grounded MAXs?



How to join/merge/concat an filled datafame with an empty dataframe by index and columns?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to merge two dictionaries in a single expression?How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)Selecting multiple columns in a pandas dataframeAdding new column to existing DataFrame in Python pandasHow to change the order of DataFrame columns?Delete column from pandas DataFrame by column name“Large data” work flows using pandasGet list from pandas DataFrame column headersHow to merge/join/concat dataframes on index in pandas



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








2















Example:



 df1 = pd.DataFrame('a':[0,0,0,0,0,0],
'b':[0,0,0,0,0,0], 'b':[0,0,0,0,0,0], index=list('abcdef'))

print (df1)


a b c
a 0 0 0
b 0 0 0
c 0 0 0
d 0 0 0
e 0 0 0
f 0 0 0

df2 = pd.DataFrame('a':range(4),
'b':[5,6,7,8], index=list('abce'))

print (df2)

a b
a 0 5
b 1 6
c 2 7
e 3 8


How do I combine the filled dataframe into the empty one that will looks like this?



 a b c
a 0 5 0
b 1 6 0
c 2 7 0
d 0 0 0
e 3 8 0
f 0 0 0


The problem is that it isn't fit for index and column.










share|improve this question













migrated from datascience.stackexchange.com Apr 4 at 1:06


This question came from our site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field.


















  • Maybe this question is related to Stackoverflow more than here.

    – Tasos
    Apr 3 at 18:15

















2















Example:



 df1 = pd.DataFrame('a':[0,0,0,0,0,0],
'b':[0,0,0,0,0,0], 'b':[0,0,0,0,0,0], index=list('abcdef'))

print (df1)


a b c
a 0 0 0
b 0 0 0
c 0 0 0
d 0 0 0
e 0 0 0
f 0 0 0

df2 = pd.DataFrame('a':range(4),
'b':[5,6,7,8], index=list('abce'))

print (df2)

a b
a 0 5
b 1 6
c 2 7
e 3 8


How do I combine the filled dataframe into the empty one that will looks like this?



 a b c
a 0 5 0
b 1 6 0
c 2 7 0
d 0 0 0
e 3 8 0
f 0 0 0


The problem is that it isn't fit for index and column.










share|improve this question













migrated from datascience.stackexchange.com Apr 4 at 1:06


This question came from our site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field.


















  • Maybe this question is related to Stackoverflow more than here.

    – Tasos
    Apr 3 at 18:15













2












2








2








Example:



 df1 = pd.DataFrame('a':[0,0,0,0,0,0],
'b':[0,0,0,0,0,0], 'b':[0,0,0,0,0,0], index=list('abcdef'))

print (df1)


a b c
a 0 0 0
b 0 0 0
c 0 0 0
d 0 0 0
e 0 0 0
f 0 0 0

df2 = pd.DataFrame('a':range(4),
'b':[5,6,7,8], index=list('abce'))

print (df2)

a b
a 0 5
b 1 6
c 2 7
e 3 8


How do I combine the filled dataframe into the empty one that will looks like this?



 a b c
a 0 5 0
b 1 6 0
c 2 7 0
d 0 0 0
e 3 8 0
f 0 0 0


The problem is that it isn't fit for index and column.










share|improve this question














Example:



 df1 = pd.DataFrame('a':[0,0,0,0,0,0],
'b':[0,0,0,0,0,0], 'b':[0,0,0,0,0,0], index=list('abcdef'))

print (df1)


a b c
a 0 0 0
b 0 0 0
c 0 0 0
d 0 0 0
e 0 0 0
f 0 0 0

df2 = pd.DataFrame('a':range(4),
'b':[5,6,7,8], index=list('abce'))

print (df2)

a b
a 0 5
b 1 6
c 2 7
e 3 8


How do I combine the filled dataframe into the empty one that will looks like this?



 a b c
a 0 5 0
b 1 6 0
c 2 7 0
d 0 0 0
e 3 8 0
f 0 0 0


The problem is that it isn't fit for index and column.







python pandas dataframe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 3 at 15:50









AnuitAnuit

111




111




migrated from datascience.stackexchange.com Apr 4 at 1:06


This question came from our site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field.









migrated from datascience.stackexchange.com Apr 4 at 1:06


This question came from our site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field.














  • Maybe this question is related to Stackoverflow more than here.

    – Tasos
    Apr 3 at 18:15

















  • Maybe this question is related to Stackoverflow more than here.

    – Tasos
    Apr 3 at 18:15
















Maybe this question is related to Stackoverflow more than here.

– Tasos
Apr 3 at 18:15





Maybe this question is related to Stackoverflow more than here.

– Tasos
Apr 3 at 18:15












1 Answer
1






active

oldest

votes


















0














Not sure if it is the most efficient way, but it works:



df3 = pd.merge(df1, df2, how='left', left_index=True, right_index=True, suffixes=('_x', ''))
df3['a'].fillna(df3['a_x'], inplace=True)
df3['b'].fillna(df3['b_x'], inplace=True)
df3.drop(['a_x', 'b_x'], axis=1, inplace=True)





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%2f55506423%2fhow-to-join-merge-concat-an-filled-datafame-with-an-empty-dataframe-by-index-and%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









    0














    Not sure if it is the most efficient way, but it works:



    df3 = pd.merge(df1, df2, how='left', left_index=True, right_index=True, suffixes=('_x', ''))
    df3['a'].fillna(df3['a_x'], inplace=True)
    df3['b'].fillna(df3['b_x'], inplace=True)
    df3.drop(['a_x', 'b_x'], axis=1, inplace=True)





    share|improve this answer



























      0














      Not sure if it is the most efficient way, but it works:



      df3 = pd.merge(df1, df2, how='left', left_index=True, right_index=True, suffixes=('_x', ''))
      df3['a'].fillna(df3['a_x'], inplace=True)
      df3['b'].fillna(df3['b_x'], inplace=True)
      df3.drop(['a_x', 'b_x'], axis=1, inplace=True)





      share|improve this answer

























        0












        0








        0







        Not sure if it is the most efficient way, but it works:



        df3 = pd.merge(df1, df2, how='left', left_index=True, right_index=True, suffixes=('_x', ''))
        df3['a'].fillna(df3['a_x'], inplace=True)
        df3['b'].fillna(df3['b_x'], inplace=True)
        df3.drop(['a_x', 'b_x'], axis=1, inplace=True)





        share|improve this answer













        Not sure if it is the most efficient way, but it works:



        df3 = pd.merge(df1, df2, how='left', left_index=True, right_index=True, suffixes=('_x', ''))
        df3['a'].fillna(df3['a_x'], inplace=True)
        df3['b'].fillna(df3['b_x'], inplace=True)
        df3.drop(['a_x', 'b_x'], axis=1, inplace=True)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 4 at 1:24









        edinhoedinho

        1965




        1965





























            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%2f55506423%2fhow-to-join-merge-concat-an-filled-datafame-with-an-empty-dataframe-by-index-and%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

            Is flight data recorder erased after every flight?When are black boxes used?What protects the location beacon (pinger) of a flight data recorder?Is there anywhere I can pick up raw flight data recorder information?Who legally owns the Flight Data Recorder?Constructing flight recorder dataWhy are FDRs and CVRs still two separate physical devices?What are the data elements shown on the GE235 flight data recorder (FDR) plot?Are CVR and FDR reset after every flight?What is the format of data stored by a Flight Data Recorder?How much data is stored in the flight data recorder per hour in a typical flight of an A380?Is a smart flight data recorder possible?

            Which is better: GPT or RelGAN for text generation?2019 Community Moderator ElectionWhat is the difference between TextGAN and LM for text generation?GANs (generative adversarial networks) possible for text as well?Generator loss not decreasing- text to image synthesisChoosing a right algorithm for template-based text generationHow should I format input and output for text generation with LSTMsGumbel Softmax vs Vanilla Softmax for GAN trainingWhich neural network to choose for classification from text/speech?NLP text autoencoder that generates text in poetic meterWhat is the interpretation of the expectation notation in the GAN formulation?What is the difference between TextGAN and LM for text generation?How to prepare the data for text generation task

            Is there a general name for the setup in which payoffs are not known exactly but players try to influence each other's perception of the payoffs?Osborne, Nash equilibria and the correctness of beliefsIs there a name for this family of games (Binomial games?)?Perfect Bayesian EquilibriumCalculating mixed strategy equilibrium in battle of sexesPure Strategy SPNEIs there a commitment mechanism which allows players to achieve pareto optimal solutions?Extensive Form GamesAn $n$-player prisoner's dilemma where a coalition of 2 players is better off defectingTit-For-Stat Strategy Best RepliesPotential solutions of the $n$-player Prisoner's Dilemma