The Python Oracle

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

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Intrigue Looping

--

Chapters
00:00 Question
03:09 Accepted answer (Score 1)
03:24 Answer 2 (Score 2)
03:57 Thank you

--

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

Question links:
[stats.friedmanchisquare]: http://docs.scipy.org/doc/scipy/referenc...
[stats.friedmanchisquare]: http://docs.scipy.org/doc/scipy/referenc...
[here]: http://reev.us/ys/df.csv
[defined here]: https://docs.python.org/2/tutorial/contr...
[better explained here]: https://stackoverflow.com/a/2921893/4992...

Accepted answer links:
["star operator"]: https://stackoverflow.com/questions/2921...

Answer 2 links:
[* (star/unpack)]: https://docs.python.org/2/tutorial/contr...

--

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])))