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

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
Pandas data frames and matplotlib.pyplot
Pandas.to_csv thousand separator
Annotating a graph with certain values of another series (Index is datetime)
Pandas rolling sum on string column

Categories

HOME
wso2-am
asp.net-core
atom-editor
activiti
isabelle
fluentd
platform-builder
sd-card
spring-cloud-stream
twitter-bootstrap-4
sqlite3
installshield
fancybox
primary-key
gorm
imacros
google-apps-marketplace
caml
windows-7-x64
aurigma
apache-metamodel
solaris-10
evopdf
ab-testing
flux
text-rendering
contextmenu
openedx
visual-composer
graphicsmagick
web-sql
dcevm
restful-authentication
log4js-node
flink-streaming
react-chartjs
key-value-observing
siesta-swift
copying
code-contracts
calibre
http-digest
x11-forwarding
sqlite2
sfdc
ruby-on-rails-3.1
g-code
grid.mvc
glew
botbuilder
firebase-admin
arena-simulation
dotcover
appcompat
prolog-setof
hendrix
clean-architecture
datastax-startup
return-value
integrity
darcs
typed-lambda-calculus
np-complete
blacklist
watchconnectivity
asp.net-4.5
xml-attribute
storekit
fuzzy-search
persist
actionbardrawertoggle
skype4py
hover-over
livequery
comobject
computer-algebra-systems
cakephp-3.1
proj4js
sorl-thumbnail
ng-animate
android-nested-fragment
device-manager
phpthumb
expected-exception
transcoding
meteor-velocity
intentservice
ivyde
quartz-graphics
tws
pygit2
clipper
specification-pattern
pvrtc
browser-detection
cisco-jtapi
pendrive
adk
fireworks
doh
xmemcached
xdomainrequest
recent-documents
appendto
krl
winbugs14
propagation
oncheckedchanged
datareader
h.323

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