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 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?
$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
And then transform into new data frame as below
- For first row if 1 is present in column 1 then output should be TT
- For first row if 1 is present in column 2 then output should be TC
- For first row if 1 is present in column 3 then output should be CC
For more detail you can refer below snip
Kindly help me to find solution using python, Its very urgent
Thanks in Advance.
python
New contributor
$endgroup$
add a comment |
$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
And then transform into new data frame as below
- For first row if 1 is present in column 1 then output should be TT
- For first row if 1 is present in column 2 then output should be TC
- For first row if 1 is present in column 3 then output should be CC
For more detail you can refer below snip
Kindly help me to find solution using python, Its very urgent
Thanks in Advance.
python
New contributor
$endgroup$
$begingroup$
Is this from a test / assignment ?
$endgroup$
– Shamit Verma
Mar 24 at 9:12
add a comment |
$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
And then transform into new data frame as below
- For first row if 1 is present in column 1 then output should be TT
- For first row if 1 is present in column 2 then output should be TC
- For first row if 1 is present in column 3 then output should be CC
For more detail you can refer below snip
Kindly help me to find solution using python, Its very urgent
Thanks in Advance.
python
New contributor
$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
And then transform into new data frame as below
- For first row if 1 is present in column 1 then output should be TT
- For first row if 1 is present in column 2 then output should be TC
- For first row if 1 is present in column 3 then output should be CC
For more detail you can refer below snip
Kindly help me to find solution using python, Its very urgent
Thanks in Advance.
python
python
New contributor
New contributor
New contributor
asked Mar 24 at 8:37
user2148754user2148754
83
83
New contributor
New contributor
$begingroup$
Is this from a test / assignment ?
$endgroup$
– Shamit Verma
Mar 24 at 9:12
add a comment |
$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
add a comment |
1 Answer
1
active
oldest
votes
$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]
Hope this helps ;) Mark this as the correct answer if you have no other doubts.
New contributor
$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
add a comment |
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.
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%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
$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]
Hope this helps ;) Mark this as the correct answer if you have no other doubts.
New contributor
$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
add a comment |
$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]
Hope this helps ;) Mark this as the correct answer if you have no other doubts.
New contributor
$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
add a comment |
$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]
Hope this helps ;) Mark this as the correct answer if you have no other doubts.
New contributor
$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]
Hope this helps ;) Mark this as the correct answer if you have no other doubts.
New contributor
New contributor
answered Mar 24 at 9:34
William ScottWilliam Scott
1063
1063
New contributor
New contributor
$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
add a comment |
$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
add a comment |
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.
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.
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%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
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
$begingroup$
Is this from a test / assignment ?
$endgroup$
– Shamit Verma
Mar 24 at 9:12