Find the most frequent number

Hello everyone,
I would like to ask how to find the most frequent number in a set of data, what should I do?

@WangJidong
In case of the data is in a datatable we can find with a group By logic. Can you share some sample data?

新建 Microsoft Excel 工作表.xlsx (8.3 KB)

First of all, thank you very much for your reply, forgive me for taking the liberty, and send you the data sheet directly, as you show, this is my data

@WangJidong
I woud suggest following:

  • configure a statistic datatable with build datatable and add 2 columns: Time, Count - output dtStatistic
  • readin the Excel file into a datatable - output dtData
  • filter DataTable on dtData and remove emtpy Time rows

in a first round we are working on string basis and not on timespan

use an assign activity:
left side: dtResult
right side:

(From d In dtData.asEnumerable
Group d By k=d(“Time”).toString.Trim into grp=Group
let ra = new Object(){k, grp.Count}
Select dtResult.Rows.Add(ra)).CopyToDataTable

with the statement dtResult.AsEnumerable.Max(Function (r) CInt(r(“Count”.toString))
the Max Count will be returned

Thank you for your reply during your busy schedule, I will try your method, you have given me great inspiration。

Perfect. We are here for help

I would like to ask, what should I do if I want to calculate the mode of a list

The list format is {1,2,3,4,5,5,4,1,1,1,2,6,8,44,11,31,5,74,26}

@WangJidong

Basically what you need is a pivot table with count of each items you can use pivot table for this.
after getting the count you can loop through datatable and add count values to an array.

Regards
Roshan

I want his value and the number of occurrences

Hello, first of all, thank you for answering my question. I want to explain that the format that exists in my data table is not the case. If this method is used, it will cause redundancy and the running time will be much longer than imagined.

I do n’t have a good algorithm to solve this problem. Similarly, I ’m also an unlucky child, so that due to work reasons, the version of UiPath is not very high, and I ca n’t invoke code. This really caused me some difficulties, if someone can solve it , Really grateful.

@WangJidong
Can you please share the output form the Group By (dtResult) or can you share a data sample describing your expected output

I can’t output because my data is very large, and the time he runs does make me anxious。

Therefore, I want to solve this problem by some algorithms, such as splitting first, and then judging the number of times, which also avoids the problem of that blank line. My blank line is not a blank line, and the data he exists is unfortunately I cannot delete it.

ok so let us do one thing. Confirm to me that your sample is valid (data sample, empty rows) and is reflecting your case. So i will pick it up later and work out a demo xaml


This is my current idea, thank you very much。

Hi @WangJidong

Please download and run this code.

Mark as solution if you found this useful :slight_smile:

Regards
RoshanCount.zip (18.9 KB)

Thank you very much for your file. I want to know what should I do when there is no Excel table and only data. I want to generate the most frequent number and how many times this number appears. I glanced at the file, It may be a bit short of what I want, but I really thank you very much and the best wishes to you.