Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi to all,
I have an excel file with 400 subjects for a study and for each one of them I have their age, their sex and 40 more columns of biological variables.

What I have tried:

import os
import numpy as np
import pandas as pd
from pandas import ExcelFile 
from pandas import ExcelWriter
import matplotlib.pyplot as plt
import seaborn as sns
from functools import reduce
import statsmodels.api as sm
from statsmodels.formula.api import ols
from scipy import stats
%matplotlib inline

>Analisi = 'C:/users.....
AnalisiISAD =pd.read_excel (r'C:\Users.....

>meanMET = Analisi.mean()
meanMET[1:41:2]    ---->these are the column I want  to do first, as a first try
MeanMETList = [...] ----> here I made the list of columns a list of only the float values from that columns (which had also a line of text)

>  grps = pd.unique(Analisi.MeanMETList.values)
d_data = {grp:Analisi['MeanMETList'][Analisi.MeanMETList == grp] for grp in grps}
k = len(pd.unique(Analisi.MeanMETList))
N = len(Analisi.values)
n = Analisi.groupby('AgeT1')       --------> here there are no errors

> SSbetween = (sum(Analisi.groupby('AgeT1').sum()['MeanMETList']**2)/n) - (Analisi['MeanMETList'].sum()**2) / N
sum_y_squared = sum([value**2 for value in Analisi['MeanMETList'].values])
SSwithin = sum_y_squared - sum(Analisi.groupby('AgeT1').sum()['MeanMETList']**2) / n
SStotal = sum_y_squared - (Analisi['MeanMETList'].sum()**2) / N

Here goes the error  TypeError: unsupported operand type(s) for /: 'float' and 'DataFrameGroupBy' "
Posted
Updated 21-May-20 0:23am

1 solution

Python
n = Analisi.groupby('AgeT1')       --------> here there are no errors

> SSbetween = (sum(Analisi.groupby('AgeT1').sum()['MeanMETList']**2)/n) - (Analisi['MeanMETList'].sum()**2) / N

You are setting variable n to a range of Analisi objects. In the next line you try to use that as a numerical value. Thus you get an error, you cannot divide by something that is not a number.
 
Share this answer
 
Comments
NeuroData Bio 21-May-20 6:35am    
Right, it makes sense...
So how can I change that without modify the Anova's formula?
Richard MacCutchan 21-May-20 6:51am    
You obviously need to set it to an actual number. I have no idea what all those formulas are supposed to be.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900