The Python Oracle

What is the correct way of passing parameters to stats.friedmanchisquare based on a DataFrame?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzling Curiosities

--

Chapters
00:00 What Is The Correct Way Of Passing Parameters To Stats.Friedmanchisquare Based On A Dataframe?
02:18 Answer 1 Score 2
02:43 Accepted Answer Score 1
02:54 Thank you

--

Full question
https://stackoverflow.com/questions/3119...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #numpy #pandas #scipy

#avk47



ANSWER 1

Score 2


The problem I see with your first attempt is that you end up passing one list with multiple dataframes inside of it.

The stats.friedmanchisquare needs multiple array_like arguments, not one list

Try using the * (star/unpack) operator to unpack the list

Like this

df = df.as_matrix()
print stats.friedmanchisquare(*[df[x, :] for x in np.arange(df.shape[0])])



ACCEPTED ANSWER

Score 1


You could pass it using the "star operator", similarly to this:

a = np.array([[1, 2, 3], [2, 3, 4] ,[4, 5, 6]])
friedmanchisquare(*(a[i, :] for i in range(a.shape[0])))