Merge Python 3 DataFrame rows that share a cell value, putting another value into a comma separated arrayFilter dataframe rows if value in column is in a set list of valuesUse a list of values to select rows from a pandas dataframeHow to drop rows of Pandas DataFrame whose value in certain columns is NaNSet value for particular cell in pandas DataFrame using indexSelect rows from a DataFrame based on values in a column in pandasDeleting DataFrame row in Pandas based on column valueMerging two DataFrames with conditionals to either update column or append rowComplex Dataframe Merge Python PandasMerge dataframes without duplicating rows in python pandasHow to merge 2 DataFrames on specific rows and columns?
Are modes in jazz primarily a melody thing?
Do the Zhentarim fire members for killing fellow members?
How do I minimise waste on a flight?
Is it safe to keep the GPU on 100% utilization for a very long time?
Good introductory book to type theory?
All of my Firefox add-ons have been disabled suddenly, how can I re-enable them?
Which "exotic salt" can lower water's freezing point by 70 °C?
Appropriate age to involve kids in life changing decisions
Convert Numbers To Emoji Math
Was there a dinosaur-counter in the original Jurassic Park movie?
Employee is self-centered and affects the team negatively
How is it believable that Euron could so easily pull off this ambush?
My large rocket is still flipping over
Does restarting the SQL Services (on the machine) clear the server cache (for things like query plans and statistics)?
An adjective or a noun to describe a very small apartment / house etc
What's weird about Proto-Indo-European Stops?
The unknown and unexplained in science fiction
Why can’t you see at the start of the Big Bang?
Why is there a cap on 401k contributions?
Can anyone identify this unknown 1988 PC card from The Palantir Corporation?
call() a function within its own context
Why were the rules for Proliferate changed?
Antivirus for Ubuntu 18.04
What chord could the notes 'F A♭ E♭' form?
Merge Python 3 DataFrame rows that share a cell value, putting another value into a comma separated array
Filter dataframe rows if value in column is in a set list of valuesUse a list of values to select rows from a pandas dataframeHow to drop rows of Pandas DataFrame whose value in certain columns is NaNSet value for particular cell in pandas DataFrame using indexSelect rows from a DataFrame based on values in a column in pandasDeleting DataFrame row in Pandas based on column valueMerging two DataFrames with conditionals to either update column or append rowComplex Dataframe Merge Python PandasMerge dataframes without duplicating rows in python pandasHow to merge 2 DataFrames on specific rows and columns?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a Python DataFrame where emails are duplicated. I'd like to find all the duplicates and merge them so that there are an array of account numbers attached to the email. I'd also like to preserve the 3rd column in the merged column.
AccountID Email Quality_3
1 blue@somedomain.com High
2 red@somedomain.com
3 blue@somedomain.com
4 green@somedomain.com Medium
5 blue@somedomain.com
6 red@somedomain.com
7 blue@somedomain.com
8 green@somedomain.com
AccountID Email Quality_3
1, 3, 5, 7 blue@somedomain.com High
2, 6 red@somedomain.com
4, 8 green@somedomain.com Medium
I am looking at left and right joins, but I can't seem to figure it out.
python python-3.x pandas dataframe merge
add a comment |
I have a Python DataFrame where emails are duplicated. I'd like to find all the duplicates and merge them so that there are an array of account numbers attached to the email. I'd also like to preserve the 3rd column in the merged column.
AccountID Email Quality_3
1 blue@somedomain.com High
2 red@somedomain.com
3 blue@somedomain.com
4 green@somedomain.com Medium
5 blue@somedomain.com
6 red@somedomain.com
7 blue@somedomain.com
8 green@somedomain.com
AccountID Email Quality_3
1, 3, 5, 7 blue@somedomain.com High
2, 6 red@somedomain.com
4, 8 green@somedomain.com Medium
I am looking at left and right joins, but I can't seem to figure it out.
python python-3.x pandas dataframe merge
add a comment |
I have a Python DataFrame where emails are duplicated. I'd like to find all the duplicates and merge them so that there are an array of account numbers attached to the email. I'd also like to preserve the 3rd column in the merged column.
AccountID Email Quality_3
1 blue@somedomain.com High
2 red@somedomain.com
3 blue@somedomain.com
4 green@somedomain.com Medium
5 blue@somedomain.com
6 red@somedomain.com
7 blue@somedomain.com
8 green@somedomain.com
AccountID Email Quality_3
1, 3, 5, 7 blue@somedomain.com High
2, 6 red@somedomain.com
4, 8 green@somedomain.com Medium
I am looking at left and right joins, but I can't seem to figure it out.
python python-3.x pandas dataframe merge
I have a Python DataFrame where emails are duplicated. I'd like to find all the duplicates and merge them so that there are an array of account numbers attached to the email. I'd also like to preserve the 3rd column in the merged column.
AccountID Email Quality_3
1 blue@somedomain.com High
2 red@somedomain.com
3 blue@somedomain.com
4 green@somedomain.com Medium
5 blue@somedomain.com
6 red@somedomain.com
7 blue@somedomain.com
8 green@somedomain.com
AccountID Email Quality_3
1, 3, 5, 7 blue@somedomain.com High
2, 6 red@somedomain.com
4, 8 green@somedomain.com Medium
I am looking at left and right joins, but I can't seem to figure it out.
python python-3.x pandas dataframe merge
python python-3.x pandas dataframe merge
edited Mar 23 at 22:13
NothingToSeeHere
asked Mar 23 at 6:16
NothingToSeeHereNothingToSeeHere
51921231
51921231
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try this:
df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
.agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
print(df_new)
Email AccountID Quality_3
0 blue@somedomain.com 1,3,5,7 High
1 green@somedomain.com 4,8 Medium
2 red@somedomain.com 2,6 None
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%2f55311147%2fmerge-python-3-dataframe-rows-that-share-a-cell-value-putting-another-value-int%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
Try this:
df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
.agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
print(df_new)
Email AccountID Quality_3
0 blue@somedomain.com 1,3,5,7 High
1 green@somedomain.com 4,8 Medium
2 red@somedomain.com 2,6 None
add a comment |
Try this:
df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
.agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
print(df_new)
Email AccountID Quality_3
0 blue@somedomain.com 1,3,5,7 High
1 green@somedomain.com 4,8 Medium
2 red@somedomain.com 2,6 None
add a comment |
Try this:
df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
.agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
print(df_new)
Email AccountID Quality_3
0 blue@somedomain.com 1,3,5,7 High
1 green@somedomain.com 4,8 Medium
2 red@somedomain.com 2,6 None
Try this:
df_new=(df.astype(str).groupby('Email')['AccountID','Quality_3']
.agg('AccountID':lambda x: ','.join(x),'Quality_3':'first').reset_index())
print(df_new)
Email AccountID Quality_3
0 blue@somedomain.com 1,3,5,7 High
1 green@somedomain.com 4,8 Medium
2 red@somedomain.com 2,6 None
answered Mar 23 at 6:23
anky_91anky_91
12.5k3922
12.5k3922
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%2f55311147%2fmerge-python-3-dataframe-rows-that-share-a-cell-value-putting-another-value-int%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