pandas data frame, apply t-test on rows simultaneously grouping by column names (have duplicates!) Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Adding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column nameHow to drop rows of Pandas DataFrame whose value in certain columns is NaN“Large data” work flows using pandasChange data type of columns in PandasSelect rows from a DataFrame based on values in a column in pandasGet statistics for each group (such as count, mean, etc) using pandas GroupBy?pandas: reshape and group row data into column dataConcat list of pandas data frame, but ignoring column nameCreate a calculated column in pandas data frame containing sorted groups

How to translate "red flag" into Spanish?

How to not starve gigantic beasts

Is this homebrew racial feat, Stonehide, balanced?

Retract an already submitted recommendation letter (written for an undergrad student)

How to count in linear time worst-case?

What is ls Largest Number Formed by only moving two sticks in 508?

Is accepting an invalid credit card number a security issue?

Identify story/novel: Tribe on colonized planet, not aware of this. "Taboo," altitude sickness, robot guardian (60s? Young Adult?)

std::is_constructible on incomplete types

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Why is this method for solving linear equations systems using determinants works?

Israeli soda type drink

Why does the Cisco show run command not show the full version, while the show version command does?

Raising a bilingual kid. When should we introduce the majority language?

What was Apollo 13's "Little Jolt" after MECO?

What is the term for a person whose job is to place products on shelves in stores?

Protagonist's race is hidden - should I reveal it?

What's parked in Mil Moscow helicopter plant?

Can I criticise the more senior developers around me for not writing clean code?

PIC mathematical operations weird problem

Co-worker works way more than he should

Flash for group photos near wall

Mistake in years of experience in resume?

What *exactly* is electrical current, voltage, and resistance?



pandas data frame, apply t-test on rows simultaneously grouping by column names (have duplicates!)



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Adding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column nameHow to drop rows of Pandas DataFrame whose value in certain columns is NaN“Large data” work flows using pandasChange data type of columns in PandasSelect rows from a DataFrame based on values in a column in pandasGet statistics for each group (such as count, mean, etc) using pandas GroupBy?pandas: reshape and group row data into column dataConcat list of pandas data frame, but ignoring column nameCreate a calculated column in pandas data frame containing sorted groups



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a data frame with particular readouts as indexes (different types of measurements for a given sample), each column is a sample for which these readouts were taken. I also have a treatment group assigned as the column name for each sample. You can see the example below.



What I need to do: for a given readout (row) group samples by treatment (column name) and perform a t-test (Welch's t-test) on each group (each treatment). T-test must be done as a comparison with one fixed treatment (control treatment). I do not care about tracking out the sample ids (it was required, now I dropped them on purpose), I'm not going to do paired tests.



For example here, for readout1 I need to compare treatment1 vs treatment3, treatment2 vs treatment3 (it's ok if I'll also get treatment3 vs treatment3).



Example of data frame:



frame = pd.DataFrame(np.arange(27).reshape((3, 9)),
index=['readout1', 'readout2', 'readout3'],
columns=['treatment1', 'treatment1', 'treatment1',
'treatment2', 'treatment2', 'treatment2',
'treatment3', 'treatment3', 'treatment3'])





frame
Out[757]:
treatment1 treatment1 ... treatment3 treatment3
readout1 0 1 ... 7 8
readout2 9 10 ... 16 17
readout3 18 19 ... 25 26

[3 rows x 9 columns]





I'm fighting it for several days now. Tried to unstack/stack the data, transposing the data frame, then grouping by index, removing nan and applying lambda. Tried other strategies but none worked. Will appreciate any help.
thank you!










share|improve this question

















  • 1





    just guessing if you print 'df'+str(e) : frame.loc[:,i] for e,i in enumerate(list(set(itertools.combinations(frame.columns,2)))) so you get the desired combinations in a dict? import itertools first

    – anky_91
    Mar 9 at 6:13












  • thanks, I did end up just transforming the table into a dictionary. I just hoped that there is a more elegant way to do it

    – rakshy
    Mar 15 at 1:08


















0















I have a data frame with particular readouts as indexes (different types of measurements for a given sample), each column is a sample for which these readouts were taken. I also have a treatment group assigned as the column name for each sample. You can see the example below.



What I need to do: for a given readout (row) group samples by treatment (column name) and perform a t-test (Welch's t-test) on each group (each treatment). T-test must be done as a comparison with one fixed treatment (control treatment). I do not care about tracking out the sample ids (it was required, now I dropped them on purpose), I'm not going to do paired tests.



For example here, for readout1 I need to compare treatment1 vs treatment3, treatment2 vs treatment3 (it's ok if I'll also get treatment3 vs treatment3).



Example of data frame:



frame = pd.DataFrame(np.arange(27).reshape((3, 9)),
index=['readout1', 'readout2', 'readout3'],
columns=['treatment1', 'treatment1', 'treatment1',
'treatment2', 'treatment2', 'treatment2',
'treatment3', 'treatment3', 'treatment3'])





frame
Out[757]:
treatment1 treatment1 ... treatment3 treatment3
readout1 0 1 ... 7 8
readout2 9 10 ... 16 17
readout3 18 19 ... 25 26

[3 rows x 9 columns]





I'm fighting it for several days now. Tried to unstack/stack the data, transposing the data frame, then grouping by index, removing nan and applying lambda. Tried other strategies but none worked. Will appreciate any help.
thank you!










share|improve this question

















  • 1





    just guessing if you print 'df'+str(e) : frame.loc[:,i] for e,i in enumerate(list(set(itertools.combinations(frame.columns,2)))) so you get the desired combinations in a dict? import itertools first

    – anky_91
    Mar 9 at 6:13












  • thanks, I did end up just transforming the table into a dictionary. I just hoped that there is a more elegant way to do it

    – rakshy
    Mar 15 at 1:08














0












0








0








I have a data frame with particular readouts as indexes (different types of measurements for a given sample), each column is a sample for which these readouts were taken. I also have a treatment group assigned as the column name for each sample. You can see the example below.



What I need to do: for a given readout (row) group samples by treatment (column name) and perform a t-test (Welch's t-test) on each group (each treatment). T-test must be done as a comparison with one fixed treatment (control treatment). I do not care about tracking out the sample ids (it was required, now I dropped them on purpose), I'm not going to do paired tests.



For example here, for readout1 I need to compare treatment1 vs treatment3, treatment2 vs treatment3 (it's ok if I'll also get treatment3 vs treatment3).



Example of data frame:



frame = pd.DataFrame(np.arange(27).reshape((3, 9)),
index=['readout1', 'readout2', 'readout3'],
columns=['treatment1', 'treatment1', 'treatment1',
'treatment2', 'treatment2', 'treatment2',
'treatment3', 'treatment3', 'treatment3'])





frame
Out[757]:
treatment1 treatment1 ... treatment3 treatment3
readout1 0 1 ... 7 8
readout2 9 10 ... 16 17
readout3 18 19 ... 25 26

[3 rows x 9 columns]





I'm fighting it for several days now. Tried to unstack/stack the data, transposing the data frame, then grouping by index, removing nan and applying lambda. Tried other strategies but none worked. Will appreciate any help.
thank you!










share|improve this question














I have a data frame with particular readouts as indexes (different types of measurements for a given sample), each column is a sample for which these readouts were taken. I also have a treatment group assigned as the column name for each sample. You can see the example below.



What I need to do: for a given readout (row) group samples by treatment (column name) and perform a t-test (Welch's t-test) on each group (each treatment). T-test must be done as a comparison with one fixed treatment (control treatment). I do not care about tracking out the sample ids (it was required, now I dropped them on purpose), I'm not going to do paired tests.



For example here, for readout1 I need to compare treatment1 vs treatment3, treatment2 vs treatment3 (it's ok if I'll also get treatment3 vs treatment3).



Example of data frame:



frame = pd.DataFrame(np.arange(27).reshape((3, 9)),
index=['readout1', 'readout2', 'readout3'],
columns=['treatment1', 'treatment1', 'treatment1',
'treatment2', 'treatment2', 'treatment2',
'treatment3', 'treatment3', 'treatment3'])





frame
Out[757]:
treatment1 treatment1 ... treatment3 treatment3
readout1 0 1 ... 7 8
readout2 9 10 ... 16 17
readout3 18 19 ... 25 26

[3 rows x 9 columns]





I'm fighting it for several days now. Tried to unstack/stack the data, transposing the data frame, then grouping by index, removing nan and applying lambda. Tried other strategies but none worked. Will appreciate any help.
thank you!






frame
Out[757]:
treatment1 treatment1 ... treatment3 treatment3
readout1 0 1 ... 7 8
readout2 9 10 ... 16 17
readout3 18 19 ... 25 26

[3 rows x 9 columns]





frame
Out[757]:
treatment1 treatment1 ... treatment3 treatment3
readout1 0 1 ... 7 8
readout2 9 10 ... 16 17
readout3 18 19 ... 25 26

[3 rows x 9 columns]






python pandas aggregate apply






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 9 at 6:04









rakshyrakshy

13




13







  • 1





    just guessing if you print 'df'+str(e) : frame.loc[:,i] for e,i in enumerate(list(set(itertools.combinations(frame.columns,2)))) so you get the desired combinations in a dict? import itertools first

    – anky_91
    Mar 9 at 6:13












  • thanks, I did end up just transforming the table into a dictionary. I just hoped that there is a more elegant way to do it

    – rakshy
    Mar 15 at 1:08













  • 1





    just guessing if you print 'df'+str(e) : frame.loc[:,i] for e,i in enumerate(list(set(itertools.combinations(frame.columns,2)))) so you get the desired combinations in a dict? import itertools first

    – anky_91
    Mar 9 at 6:13












  • thanks, I did end up just transforming the table into a dictionary. I just hoped that there is a more elegant way to do it

    – rakshy
    Mar 15 at 1:08








1




1





just guessing if you print 'df'+str(e) : frame.loc[:,i] for e,i in enumerate(list(set(itertools.combinations(frame.columns,2)))) so you get the desired combinations in a dict? import itertools first

– anky_91
Mar 9 at 6:13






just guessing if you print 'df'+str(e) : frame.loc[:,i] for e,i in enumerate(list(set(itertools.combinations(frame.columns,2)))) so you get the desired combinations in a dict? import itertools first

– anky_91
Mar 9 at 6:13














thanks, I did end up just transforming the table into a dictionary. I just hoped that there is a more elegant way to do it

– rakshy
Mar 15 at 1:08






thanks, I did end up just transforming the table into a dictionary. I just hoped that there is a more elegant way to do it

– rakshy
Mar 15 at 1:08













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%2f55074508%2fpandas-data-frame-apply-t-test-on-rows-simultaneously-grouping-by-column-names%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%2f55074508%2fpandas-data-frame-apply-t-test-on-rows-simultaneously-grouping-by-column-names%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

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович