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;
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
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.
add a comment |
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
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
add a comment |
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
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
python pandas dataframe
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
add a comment |
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)
add a comment |
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)
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)
answered Apr 4 at 1:24
edinhoedinho
1965
1965
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Maybe this question is related to Stackoverflow more than here.
– Tasos
Apr 3 at 18:15