Find the maximum and minimum

chuxin huo
2 min readMay 20, 2021

Find locations

The Excel file book1.xlsx with the proportion of materials, as shown in the figure below:

Every two columns in the file form a group. The odd-numbered column is the material name, and the even-numbered column is the material proportion. Now we need to find the material name with the largest proportion in each row.

Write SPL script:

A1 Read the data in the file book1.xlsx, the option @w means read as the sequence of a sequence.

A2 Loop through each row of data sequence starting from the second row in A1, ~.step(2,2).pmax()starts from the second column and takes the number every two columns, namely 2, 4, 6….. The values of the column form a sequence, and find the serial number of the maximum value in the sequence; in the same way, ~.step(2,1) takes the number every two columns starting from the first column, namely 1, 3, 5. The value of the column forms a sequence, and then the value corresponding to the maximum number is taken out of this sequence.

Find members

There is a list of months in file book1, which will appear indefinitely every month. The screenshot of the data is as follows:

Now we need to find the month with the least number of occurrences, and if there are more than one, find out together.

Write SPL script:

A1 Read the data in the file book1.xlsx

A2 After grouping by Months, select the group with the smallest number of members in the group and return the Months of each group. The option @a means to select all groups that meet the conditions.

--

--