Creating new columns based on 3 column and create new data frame The Next CEO of Stack Overflow2019 Community Moderator ElectionWhere is the error in the following code?Imputation of missing values and dealing with categorical valuesUsing pandas, check a column for matching text and update new column if TRUECreate new data frames from existing data frame based on unique column valuesA single column has many values per row, separated by a comma. How to create an individual column for each of these?Pandas - how can I calculate a field to count the number of occurences that values in the ID field appear in sequential orderHow to write formula inside the loop to run this code in every hour continously in every day in panda pythonMulti Class Text Classification?Time series data into supervised learning problem PythonFinding weights of independent features with an artificial neural network?

How to get from Geneva Airport to Metabief?

What is the difference between 翼 and 翅膀?

WOW air has ceased operation, can I get my tickets refunded?

Is it possible to replace duplicates of a character with one character using tr

unclear about Dynamic Binding

What connection does MS Office have to Netscape Navigator?

Why this way of making earth uninhabitable in Interstellar?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Inappropriate reference requests from Journal reviewers

Make solar eclipses exceedingly rare, but still have new moons

Why isn't the Mueller report being released completely and unredacted?

Why, when going from special to general relativity, do we just replace partial derivatives with covariant derivatives?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

If the updated MCAS software needs two AOA sensors, doesn't that introduce a new single point of failure?

Decomposition of product of two Plucker coordinates

What did we know about the Kessel run before the prologues?

What flight has the highest ratio of time difference to flight time?

Flying from Cape Town to England and return to another province

Is it professional to write unrelated content in an almost-empty email?

Why does the flight controls check come before arming the autobrake on the A320?

Ubuntu shell scripting

What happens if you roll doubles 3 times then land on "Go to jail?"

Why is information "lost" when it got into a black hole?

Why didn't Khan get resurrected in the Genesis Explosion?



Creating new columns based on 3 column and create new data frame



The Next CEO of Stack Overflow
2019 Community Moderator ElectionWhere is the error in the following code?Imputation of missing values and dealing with categorical valuesUsing pandas, check a column for matching text and update new column if TRUECreate new data frames from existing data frame based on unique column valuesA single column has many values per row, separated by a comma. How to create an individual column for each of these?Pandas - how can I calculate a field to count the number of occurences that values in the ID field appear in sequential orderHow to write formula inside the loop to run this code in every hour continously in every day in panda pythonMulti Class Text Classification?Time series data into supervised learning problem PythonFinding weights of independent features with an artificial neural network?










1












$begingroup$


Heading



Consider my data frame
rs123 T C 0 0 1 1 0 0 1 0 0 1 0 0
rs124 T C 0 0 1 0 0 1 0 0 1 0 0 1
rs125 A A 1 0 0 1 0 0 1 0 0 1 0 0



Similarity, i have total 93 columns excluding first three



I want to create my data as



enter image description here



And then transform into new data frame as below



  1. For first row if 1 is present in column 1 then output should be TT

  2. For first row if 1 is present in column 2 then output should be TC

  3. For first row if 1 is present in column 3 then output should be CC

For more detail you can refer below snip



enter image description here



Kindly help me to find solution using python, Its very urgent



Thanks in Advance.










share|improve this question







New contributor




user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    Is this from a test / assignment ?
    $endgroup$
    – Shamit Verma
    Mar 24 at 9:12















1












$begingroup$


Heading



Consider my data frame
rs123 T C 0 0 1 1 0 0 1 0 0 1 0 0
rs124 T C 0 0 1 0 0 1 0 0 1 0 0 1
rs125 A A 1 0 0 1 0 0 1 0 0 1 0 0



Similarity, i have total 93 columns excluding first three



I want to create my data as



enter image description here



And then transform into new data frame as below



  1. For first row if 1 is present in column 1 then output should be TT

  2. For first row if 1 is present in column 2 then output should be TC

  3. For first row if 1 is present in column 3 then output should be CC

For more detail you can refer below snip



enter image description here



Kindly help me to find solution using python, Its very urgent



Thanks in Advance.










share|improve this question







New contributor




user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    Is this from a test / assignment ?
    $endgroup$
    – Shamit Verma
    Mar 24 at 9:12













1












1








1





$begingroup$


Heading



Consider my data frame
rs123 T C 0 0 1 1 0 0 1 0 0 1 0 0
rs124 T C 0 0 1 0 0 1 0 0 1 0 0 1
rs125 A A 1 0 0 1 0 0 1 0 0 1 0 0



Similarity, i have total 93 columns excluding first three



I want to create my data as



enter image description here



And then transform into new data frame as below



  1. For first row if 1 is present in column 1 then output should be TT

  2. For first row if 1 is present in column 2 then output should be TC

  3. For first row if 1 is present in column 3 then output should be CC

For more detail you can refer below snip



enter image description here



Kindly help me to find solution using python, Its very urgent



Thanks in Advance.










share|improve this question







New contributor




user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




Heading



Consider my data frame
rs123 T C 0 0 1 1 0 0 1 0 0 1 0 0
rs124 T C 0 0 1 0 0 1 0 0 1 0 0 1
rs125 A A 1 0 0 1 0 0 1 0 0 1 0 0



Similarity, i have total 93 columns excluding first three



I want to create my data as



enter image description here



And then transform into new data frame as below



  1. For first row if 1 is present in column 1 then output should be TT

  2. For first row if 1 is present in column 2 then output should be TC

  3. For first row if 1 is present in column 3 then output should be CC

For more detail you can refer below snip



enter image description here



Kindly help me to find solution using python, Its very urgent



Thanks in Advance.







python






share|improve this question







New contributor




user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 24 at 8:37









user2148754user2148754

83




83




New contributor




user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user2148754 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • $begingroup$
    Is this from a test / assignment ?
    $endgroup$
    – Shamit Verma
    Mar 24 at 9:12
















  • $begingroup$
    Is this from a test / assignment ?
    $endgroup$
    – Shamit Verma
    Mar 24 at 9:12















$begingroup$
Is this from a test / assignment ?
$endgroup$
– Shamit Verma
Mar 24 at 9:12




$begingroup$
Is this from a test / assignment ?
$endgroup$
– Shamit Verma
Mar 24 at 9:12










1 Answer
1






active

oldest

votes


















0












$begingroup$

The question could have been framed better. Checkout the code below, in which your final dataframe will be in output.



import pandas as pd

input_array = [["rs123", "T", "C", 0, 0, 1, 1, 0, 0, 1, 0, 0], ["rs124", "A", "G", 0, 0, 1, 0, 1, 0, 0, 0, 1]]

raw_pd = pd.DataFrame(input_array).astype(str)

def change(a):
if list(a)[2]+list(a)[3]+list(a)[4] == "100":
return list(a)[0] + list(a)[0]
elif list(a)[2]+list(a)[3]+list(a)[4] == "010":
return list(a)[0] + list(a)[1]
else:
return list(a)[1] + list(a)[1]

output = pd.DataFrame()

output['S1'] = raw_pd[[1, 2, 3, 4, 5]].apply(lambda x: change(x), axis = 1)

output['S2'] = raw_pd[[1, 2, 6, 7, 8]].apply(lambda x: change(x), axis = 1)

output['S3'] = raw_pd[[1, 2, 9, 10, 11]].apply(lambda x: change(x), axis = 1)

output['SNP'] = raw_pd[0]


enter image description here



Hope this helps ;) Mark this as the correct answer if you have no other doubts.






share|improve this answer








New contributor




William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$












  • $begingroup$
    Hi William, Thanks for your help. This worked (Y) Also, regarding question framing will take care of it.
    $endgroup$
    – user2148754
    Mar 24 at 12:00











Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);



);






user2148754 is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47885%2fcreating-new-columns-based-on-3-column-and-create-new-data-frame%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












$begingroup$

The question could have been framed better. Checkout the code below, in which your final dataframe will be in output.



import pandas as pd

input_array = [["rs123", "T", "C", 0, 0, 1, 1, 0, 0, 1, 0, 0], ["rs124", "A", "G", 0, 0, 1, 0, 1, 0, 0, 0, 1]]

raw_pd = pd.DataFrame(input_array).astype(str)

def change(a):
if list(a)[2]+list(a)[3]+list(a)[4] == "100":
return list(a)[0] + list(a)[0]
elif list(a)[2]+list(a)[3]+list(a)[4] == "010":
return list(a)[0] + list(a)[1]
else:
return list(a)[1] + list(a)[1]

output = pd.DataFrame()

output['S1'] = raw_pd[[1, 2, 3, 4, 5]].apply(lambda x: change(x), axis = 1)

output['S2'] = raw_pd[[1, 2, 6, 7, 8]].apply(lambda x: change(x), axis = 1)

output['S3'] = raw_pd[[1, 2, 9, 10, 11]].apply(lambda x: change(x), axis = 1)

output['SNP'] = raw_pd[0]


enter image description here



Hope this helps ;) Mark this as the correct answer if you have no other doubts.






share|improve this answer








New contributor




William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$












  • $begingroup$
    Hi William, Thanks for your help. This worked (Y) Also, regarding question framing will take care of it.
    $endgroup$
    – user2148754
    Mar 24 at 12:00















0












$begingroup$

The question could have been framed better. Checkout the code below, in which your final dataframe will be in output.



import pandas as pd

input_array = [["rs123", "T", "C", 0, 0, 1, 1, 0, 0, 1, 0, 0], ["rs124", "A", "G", 0, 0, 1, 0, 1, 0, 0, 0, 1]]

raw_pd = pd.DataFrame(input_array).astype(str)

def change(a):
if list(a)[2]+list(a)[3]+list(a)[4] == "100":
return list(a)[0] + list(a)[0]
elif list(a)[2]+list(a)[3]+list(a)[4] == "010":
return list(a)[0] + list(a)[1]
else:
return list(a)[1] + list(a)[1]

output = pd.DataFrame()

output['S1'] = raw_pd[[1, 2, 3, 4, 5]].apply(lambda x: change(x), axis = 1)

output['S2'] = raw_pd[[1, 2, 6, 7, 8]].apply(lambda x: change(x), axis = 1)

output['S3'] = raw_pd[[1, 2, 9, 10, 11]].apply(lambda x: change(x), axis = 1)

output['SNP'] = raw_pd[0]


enter image description here



Hope this helps ;) Mark this as the correct answer if you have no other doubts.






share|improve this answer








New contributor




William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$












  • $begingroup$
    Hi William, Thanks for your help. This worked (Y) Also, regarding question framing will take care of it.
    $endgroup$
    – user2148754
    Mar 24 at 12:00













0












0








0





$begingroup$

The question could have been framed better. Checkout the code below, in which your final dataframe will be in output.



import pandas as pd

input_array = [["rs123", "T", "C", 0, 0, 1, 1, 0, 0, 1, 0, 0], ["rs124", "A", "G", 0, 0, 1, 0, 1, 0, 0, 0, 1]]

raw_pd = pd.DataFrame(input_array).astype(str)

def change(a):
if list(a)[2]+list(a)[3]+list(a)[4] == "100":
return list(a)[0] + list(a)[0]
elif list(a)[2]+list(a)[3]+list(a)[4] == "010":
return list(a)[0] + list(a)[1]
else:
return list(a)[1] + list(a)[1]

output = pd.DataFrame()

output['S1'] = raw_pd[[1, 2, 3, 4, 5]].apply(lambda x: change(x), axis = 1)

output['S2'] = raw_pd[[1, 2, 6, 7, 8]].apply(lambda x: change(x), axis = 1)

output['S3'] = raw_pd[[1, 2, 9, 10, 11]].apply(lambda x: change(x), axis = 1)

output['SNP'] = raw_pd[0]


enter image description here



Hope this helps ;) Mark this as the correct answer if you have no other doubts.






share|improve this answer








New contributor




William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$



The question could have been framed better. Checkout the code below, in which your final dataframe will be in output.



import pandas as pd

input_array = [["rs123", "T", "C", 0, 0, 1, 1, 0, 0, 1, 0, 0], ["rs124", "A", "G", 0, 0, 1, 0, 1, 0, 0, 0, 1]]

raw_pd = pd.DataFrame(input_array).astype(str)

def change(a):
if list(a)[2]+list(a)[3]+list(a)[4] == "100":
return list(a)[0] + list(a)[0]
elif list(a)[2]+list(a)[3]+list(a)[4] == "010":
return list(a)[0] + list(a)[1]
else:
return list(a)[1] + list(a)[1]

output = pd.DataFrame()

output['S1'] = raw_pd[[1, 2, 3, 4, 5]].apply(lambda x: change(x), axis = 1)

output['S2'] = raw_pd[[1, 2, 6, 7, 8]].apply(lambda x: change(x), axis = 1)

output['S3'] = raw_pd[[1, 2, 9, 10, 11]].apply(lambda x: change(x), axis = 1)

output['SNP'] = raw_pd[0]


enter image description here



Hope this helps ;) Mark this as the correct answer if you have no other doubts.







share|improve this answer








New contributor




William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered Mar 24 at 9:34









William ScottWilliam Scott

1063




1063




New contributor




William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






William Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • $begingroup$
    Hi William, Thanks for your help. This worked (Y) Also, regarding question framing will take care of it.
    $endgroup$
    – user2148754
    Mar 24 at 12:00
















  • $begingroup$
    Hi William, Thanks for your help. This worked (Y) Also, regarding question framing will take care of it.
    $endgroup$
    – user2148754
    Mar 24 at 12:00















$begingroup$
Hi William, Thanks for your help. This worked (Y) Also, regarding question framing will take care of it.
$endgroup$
– user2148754
Mar 24 at 12:00




$begingroup$
Hi William, Thanks for your help. This worked (Y) Also, regarding question framing will take care of it.
$endgroup$
– user2148754
Mar 24 at 12:00










user2148754 is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















user2148754 is a new contributor. Be nice, and check out our Code of Conduct.












user2148754 is a new contributor. Be nice, and check out our Code of Conduct.











user2148754 is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Data Science Stack Exchange!


  • 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.

Use MathJax to format equations. MathJax reference.


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%2fdatascience.stackexchange.com%2fquestions%2f47885%2fcreating-new-columns-based-on-3-column-and-create-new-data-frame%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

Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

Tähtien Talli Jäsenet | Lähteet | NavigointivalikkoSuomen Hippos – Tähtien Talli

Do these cracks on my tires look bad? The Next CEO of Stack OverflowDry rot tire should I replace?Having to replace tiresFishtailed so easily? Bad tires? ABS?Filling the tires with something other than air, to avoid puncture hassles?Used Michelin tires safe to install?Do these tyre cracks necessitate replacement?Rumbling noise: tires or mechanicalIs it possible to fix noisy feathered tires?Are bad winter tires still better than summer tires in winter?Torque converter failure - Related to replacing only 2 tires?Why use snow tires on all 4 wheels on 2-wheel-drive cars?