Create columns of array values based on multiple conditions on column from other dataframe










0















I am new to Python. I need to create a dataframe column - (array-like) based on condition and extract it from other dataframe.



df-



Date A App T
1/12/2018 1 ABC 1
1/13/2018 2 DDC 2
1/14/2018 3 SDC 3
1/15/2018 4 MDC 4
1/16/2018 1 ABC 8


df2-



A H App
1 H1 ABC
1 H2 ABC
1 H3 ABC
1 H4 ABC
2 H5 DDC
2 H1 DDC
3 H2 SDC
3 H5 SDC
4 H3 MDC


Desired Result-



I need to add another column (OtherApp) to df as below (Just few samples are shown)-



Date A App T OtherApp
1/12/2018 1 ABC 1 [DDC,SDC,MDC]
1/13/2018 2 DDC 2 [ABC,SDC]
1/14/2018 3 SDC 3 [ABC,DDC]
1/15/2018 4 MDC 4 [ABC]


Logic behind this -



  1. Take A for each value T (unique- valued column) column from df .

  2. Match the A with df2 data and get all the H associated to the particular A value.

  3. Get all the App hosted in the H values obtained from step-2.

Greatly appreciate any help!










share|improve this question



















  • 2





    What have you tried so far? Also, please post data as text, not images. We can't copy and paste from this.

    – Peter Leimbigler
    Nov 16 '18 at 1:03












  • Sorry, didn't knew images create issue for Copy + Paste. I tried a for loop for each record in df and used a loc functionality inside to get the list of values of H from df2, but it doesn't too right and was not able to obtain the list of values of H.

    – Sparsha Devapalli
    Nov 16 '18 at 2:05











  • Please edit your post to add the code you have tried, its difficult for us to see where your issue is without your code. But for output 1 you can try: idx, unique_values = np.unique(df.A,return_index=True)

    – Jetman
    Nov 16 '18 at 5:44















0















I am new to Python. I need to create a dataframe column - (array-like) based on condition and extract it from other dataframe.



df-



Date A App T
1/12/2018 1 ABC 1
1/13/2018 2 DDC 2
1/14/2018 3 SDC 3
1/15/2018 4 MDC 4
1/16/2018 1 ABC 8


df2-



A H App
1 H1 ABC
1 H2 ABC
1 H3 ABC
1 H4 ABC
2 H5 DDC
2 H1 DDC
3 H2 SDC
3 H5 SDC
4 H3 MDC


Desired Result-



I need to add another column (OtherApp) to df as below (Just few samples are shown)-



Date A App T OtherApp
1/12/2018 1 ABC 1 [DDC,SDC,MDC]
1/13/2018 2 DDC 2 [ABC,SDC]
1/14/2018 3 SDC 3 [ABC,DDC]
1/15/2018 4 MDC 4 [ABC]


Logic behind this -



  1. Take A for each value T (unique- valued column) column from df .

  2. Match the A with df2 data and get all the H associated to the particular A value.

  3. Get all the App hosted in the H values obtained from step-2.

Greatly appreciate any help!










share|improve this question



















  • 2





    What have you tried so far? Also, please post data as text, not images. We can't copy and paste from this.

    – Peter Leimbigler
    Nov 16 '18 at 1:03












  • Sorry, didn't knew images create issue for Copy + Paste. I tried a for loop for each record in df and used a loc functionality inside to get the list of values of H from df2, but it doesn't too right and was not able to obtain the list of values of H.

    – Sparsha Devapalli
    Nov 16 '18 at 2:05











  • Please edit your post to add the code you have tried, its difficult for us to see where your issue is without your code. But for output 1 you can try: idx, unique_values = np.unique(df.A,return_index=True)

    – Jetman
    Nov 16 '18 at 5:44













0












0








0








I am new to Python. I need to create a dataframe column - (array-like) based on condition and extract it from other dataframe.



df-



Date A App T
1/12/2018 1 ABC 1
1/13/2018 2 DDC 2
1/14/2018 3 SDC 3
1/15/2018 4 MDC 4
1/16/2018 1 ABC 8


df2-



A H App
1 H1 ABC
1 H2 ABC
1 H3 ABC
1 H4 ABC
2 H5 DDC
2 H1 DDC
3 H2 SDC
3 H5 SDC
4 H3 MDC


Desired Result-



I need to add another column (OtherApp) to df as below (Just few samples are shown)-



Date A App T OtherApp
1/12/2018 1 ABC 1 [DDC,SDC,MDC]
1/13/2018 2 DDC 2 [ABC,SDC]
1/14/2018 3 SDC 3 [ABC,DDC]
1/15/2018 4 MDC 4 [ABC]


Logic behind this -



  1. Take A for each value T (unique- valued column) column from df .

  2. Match the A with df2 data and get all the H associated to the particular A value.

  3. Get all the App hosted in the H values obtained from step-2.

Greatly appreciate any help!










share|improve this question
















I am new to Python. I need to create a dataframe column - (array-like) based on condition and extract it from other dataframe.



df-



Date A App T
1/12/2018 1 ABC 1
1/13/2018 2 DDC 2
1/14/2018 3 SDC 3
1/15/2018 4 MDC 4
1/16/2018 1 ABC 8


df2-



A H App
1 H1 ABC
1 H2 ABC
1 H3 ABC
1 H4 ABC
2 H5 DDC
2 H1 DDC
3 H2 SDC
3 H5 SDC
4 H3 MDC


Desired Result-



I need to add another column (OtherApp) to df as below (Just few samples are shown)-



Date A App T OtherApp
1/12/2018 1 ABC 1 [DDC,SDC,MDC]
1/13/2018 2 DDC 2 [ABC,SDC]
1/14/2018 3 SDC 3 [ABC,DDC]
1/15/2018 4 MDC 4 [ABC]


Logic behind this -



  1. Take A for each value T (unique- valued column) column from df .

  2. Match the A with df2 data and get all the H associated to the particular A value.

  3. Get all the App hosted in the H values obtained from step-2.

Greatly appreciate any help!







python pandas dataframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 2:02







Sparsha Devapalli

















asked Nov 16 '18 at 0:47









Sparsha DevapalliSparsha Devapalli

596




596







  • 2





    What have you tried so far? Also, please post data as text, not images. We can't copy and paste from this.

    – Peter Leimbigler
    Nov 16 '18 at 1:03












  • Sorry, didn't knew images create issue for Copy + Paste. I tried a for loop for each record in df and used a loc functionality inside to get the list of values of H from df2, but it doesn't too right and was not able to obtain the list of values of H.

    – Sparsha Devapalli
    Nov 16 '18 at 2:05











  • Please edit your post to add the code you have tried, its difficult for us to see where your issue is without your code. But for output 1 you can try: idx, unique_values = np.unique(df.A,return_index=True)

    – Jetman
    Nov 16 '18 at 5:44












  • 2





    What have you tried so far? Also, please post data as text, not images. We can't copy and paste from this.

    – Peter Leimbigler
    Nov 16 '18 at 1:03












  • Sorry, didn't knew images create issue for Copy + Paste. I tried a for loop for each record in df and used a loc functionality inside to get the list of values of H from df2, but it doesn't too right and was not able to obtain the list of values of H.

    – Sparsha Devapalli
    Nov 16 '18 at 2:05











  • Please edit your post to add the code you have tried, its difficult for us to see where your issue is without your code. But for output 1 you can try: idx, unique_values = np.unique(df.A,return_index=True)

    – Jetman
    Nov 16 '18 at 5:44







2




2





What have you tried so far? Also, please post data as text, not images. We can't copy and paste from this.

– Peter Leimbigler
Nov 16 '18 at 1:03






What have you tried so far? Also, please post data as text, not images. We can't copy and paste from this.

– Peter Leimbigler
Nov 16 '18 at 1:03














Sorry, didn't knew images create issue for Copy + Paste. I tried a for loop for each record in df and used a loc functionality inside to get the list of values of H from df2, but it doesn't too right and was not able to obtain the list of values of H.

– Sparsha Devapalli
Nov 16 '18 at 2:05





Sorry, didn't knew images create issue for Copy + Paste. I tried a for loop for each record in df and used a loc functionality inside to get the list of values of H from df2, but it doesn't too right and was not able to obtain the list of values of H.

– Sparsha Devapalli
Nov 16 '18 at 2:05













Please edit your post to add the code you have tried, its difficult for us to see where your issue is without your code. But for output 1 you can try: idx, unique_values = np.unique(df.A,return_index=True)

– Jetman
Nov 16 '18 at 5:44





Please edit your post to add the code you have tried, its difficult for us to see where your issue is without your code. But for output 1 you can try: idx, unique_values = np.unique(df.A,return_index=True)

– Jetman
Nov 16 '18 at 5:44












0






active

oldest

votes











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%2f53329884%2fcreate-columns-of-array-values-based-on-multiple-conditions-on-column-from-other%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f53329884%2fcreate-columns-of-array-values-based-on-multiple-conditions-on-column-from-other%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

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

Evgeni Malkin