Python Forum
Pandas find the most often rows - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Pandas find the most often rows (/thread-18945.html)



Pandas find the most often rows - dervast - Jun-07-2019

Hi.
I have a panda Data Frame like the one below
smallData=pd.DataFrame(np.array([[1,2,3,4,5],[4,5,6,7,8],[1,2,3,3,3],[1,2,2,3,3],[1,2,3,5,3],[1,2,3,5,3]]),columns=['1', '2','3','4','5'])
and I would like to find which are the most frequent sequences, where each row is considered a 5 step sequence.

I do not want to find only the most frequent one but for each sequence to get back a number of how frequent it appeared.

Any suggestions?
Regards
Alex


RE: Pandas find the most often rows - ichabod801 - Jun-07-2019

Don't make a dataframe. Make it a list of tuples, and run it through collections.Counter.