I have a column RESULT
which has digits of length 11 in each and the schema of the same is:
RESULT: string (nullable = true)
Now, I want to perform the below operation and update a new column which will add an extra digit at last. The example shown below is for first number 03600024145
Note: I don't want to change the format of table to pandas but do everything in Pyspark dataframe.
- Add the odd number digits: 0+6+0+2+1+5 = 14.
- Multiply the result by 3: 14 × 3 = 42.
- Add the even number digits: 3+0+0+4+4 = 11.
- Add the two results together: 42 + 11 = 53.
- To calculate the check digit, take the remainder of (53 / 10), which is also known as (53 modulo 10), and if not 0, subtract from 10. Therefore, the check digit value is 7. i.e. (53 / 10) = 5 remainder 3; 10 - 3 = 7.
- Add this check digit at last. So the number becomes
036000241457
So, if this logic is applied to the whole column the result will become as UPDATED RESULT
For further clarification of logic :https://en.wikipedia.org/wiki/Check_digit#UPC
There is a similar python code but a bit different at step-5: python: create check digit function