0

I have run ANOVA analysis using statsmodel library as following:

import numpy as np
import pandas as pd
from scipy import stats
from scipy.stats import norm
from scipy.signal import savgol_filter
from matplotlib import rcParams
import scipy.stats as stats


#ANOVA ONE WAY
mc = MultiComparison(df['NDVI'], df['line'])
mc_resultsNDVI = mc.tukeyhsd()
print(mc_resultsNDVI)

The problem: I would like to get the result as pandas dataframe. Now, when I print the result (and I have run this test for few columns) I get something that looks like this:

I would like it to be pandas dataframe

Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
Aitor Almon
  • 25
  • 1
  • 5
  • Please set up [reproducible example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) that includes runnable code with data sample. What is `MultiComparison`? Also, results look like named tuples where you can map values to dictionary/list for `pandas.DataFrame()` constructor. Give it a try – Parfait Feb 18 '20 at 15:33

1 Answers1

0

You use the summary() method and convert it into a dataframe:

import numpy as np
import pandas as pd
from statsmodels.sandbox.stats.multicomp import MultiComparison

from sklearn.datasets import load_iris
iris = load_iris()
df = pd.DataFrame(data= iris['data'],
                     columns= iris['feature_names'] )
df['target'] = iris['target']

pd.DataFrame(mc_resultsNDVI.summary())

    0   1   2   3   4   5   6
0   group1  group2  meandiff    p-adj   lower   upper   reject
1   0   1   2.798   0.001   2.5942  3.0018  True
2   0   2   4.09    0.001   3.8862  4.2938  True
3   1   2   1.292   0.001   1.0882  1.4958  True
StupidWolf
  • 45,075
  • 17
  • 40
  • 72