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

            Quoting Keynes in a lectureIs differentiated instruction permitted by universities?How to make students learn prerequisitesUnsatisfactory Instructor Evaluations: balancing of expectations of engineering studentsWhat is the difference between a “statistician”, “applied statistician”, and an academic applying advanced stats within their field?Listing in reference section, but not quotingHow to efficiently use time while preparing for a class?Graduate Admissions: Teaching Emphasisstrategies for sharing teaching information with universities I don't personally have contacts withIs there an efficient way to give a large class of students feedback about their assignments?Is it unreasonable to expect students to read the lecture notes before attending the first class?

            Rank groups within a grouped sequence of TRUE/FALSE and NAGrouping functions (tapply, by, aggregate) and the *apply familyCharacters counting and subletting specific patternsWhat is the purpose of setting a key in data.table?data.table vs dplyr: can one do something well the other can't or does poorly?how to make a bar plot for a list of dataframes?How to group by unique values in a list in RPandas - Alternative to rank() function that gives unique ordinal ranks for a columnRank within group in for loop in RData transformation: from dyadic to observational data in RGetting map from purrr to work with paste0

            Are all passive ability checks floors for active ability checks?Does passive perception supersede active perception?Which skills can be used passively?Active Opposition with Free-Form Professions in Fate5E Trap/Ambush/Stealth Mechanics VS Passive Perception ConfusionInteraction between perception and stealth in obscured conditionsHow does Keen Sight affect Passive Perception?Are all d20 rolls either attacks, saves or ability checks?Can players declare that they are making a specific ability check?Can I see a Hidden creature that is not obscured at all?Can a Stealth check ever be made passively?Is this alternate version of the Observant feat balanced?What is the minimum amount of skill points per HD?