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

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?

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?