pandas


Pandas: aggregation on multi-level groups


I have a df that looks something like this:
batch group reading temp test block delay
0 9551 Control 340 22.9 1 X 35
1 9551 Control 345 22.9 1 Y 35
I need to group by 'group' and 'block', e.g. my means would look like so:
df.groupby(['block', 'group']).reading.mean().unstack().transpose()
block X Y
group
Control 347.339450 350.427273
Trial 347.790909 350.668182
What would be the best way to call a 2 argument function like scipy.stats.ttest_ind on data sliced this way so I end up with a table of t tests for
control vs trial in x
control vs trial in y
x vs y in control
x vs y in trial
Do you want to group and aggregate the data before applying the t-test? I think you want to select subsets of the data. Grouping can do that, but masking might get the job done more simply.
Offhand, I'd say you want something like
scipy.stats.ttest_ind(df[(df.group == 'Control') & (df.block == 'X')].reading,
df[(df.group == 'Trial') & (df.block == 'X')].reading)

Related Links

Merging two dataframes based on a date between two other dates without a common column
Why I can't change the series format?
Copy numpy array into Panda multiindex (same size)
Average Previous and Current Row - Pandas
seaborn pointplot above swarmplot
Edit field and append value to a python dataframe column
column_stack returns non cotiguous array
pandas: conditionally select a row cell for each column based on a mask
pandas custom function apply on melted dataframe
How to check for boolean codition in pandas dataframe
Reading batches of data from BigQuery into Datalab
Jupyter/ipywidgets sorting dataframe on two levels
Groupby.sum() giving ValueError: overflow in timedelta operation
Why does DataFrameGroupBy.boxplot method throw error when given argument “subplots=True/False”?
Calculate age in months - optimize date transformations in pandas
pandas: list of dictionaries grouped by key from df

Categories

HOME
ibm-bluemix
twitter
arduino-uno
ionic-framework
date
hive
deployment
keras
reflection
fluentd
mean-stack
rsync
jira
leon
amazon-ecs
wamp
timeout
fallback
uitypeeditor
footer
beyondcompare
crystal-reports-2008
predix
spark-jobserver
elasticsearch-net
msys2
primitive
librato
junit5
yadcf
windows-dev-center
subset-sum
sequential
http-digest
suricata
adobe-premiere
automake
multilingual
unspecified
vapor
firebase-admin
keydown
user-accounts
jedis
zip4j
worksheet
fancybox-2
pg-dump
pearson
mcafee
jspdf-autotable
spring-mongodb
titanium-android
vtigercrm
py2app
paypal-express
pagerank
php-internals
hsv
iad
vhd
marching-cubes
qdialog
fouc
cakephp-3.1
remobjects
graph-api-explorer
dereference
bridge.net
e10s
kineticjs
asp.net-web-api-odata
terminfo
industrial
xsockets.net
sitemesh
jmapviewer
ruby-datamapper
orchardcms-1.7
spring-validator
eventlistener
cassini-dev
selected
path-separator
newtonscript
nsmanagedobject
subscript
vdsp
tomcat-valve
self-extracting
lang
asp.net-mvc-areas
zend-translate
substrings
audio-capture
project-hosting
aquaticprime
post-build
data-acquisition
windows-live-messenger

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App