Search code examples
pythonpandasapplypython-applymap

Why apply function did not work on pandas dataframe


ct_data['IM NO'] = ct_data['IM NO'].apply(lambda x: pyffx.Integer(b'dkrya@Jppl1994', length=20).encrypt(int(x)))

I am trying to encyrpt here is below head of ct_data

 Unnamed: 0      IM NO                                              CT ID
0           0  214281340  x1E5e3ukRyEFRT6SUAF6lg|d543d3d064da465b8576d87
1           1  214281244  -vf6738ee3bedf47e8acf4613034069ab0|aa0d2dac654
2           2  175326863  __g3d877adf9d154637be26d9a0111e1cd6|6FfHZRoiWs
3           3  299631931  __gbe204670ca784a01b7207b42a7e5a5d3|54e2c39cd3
4           4  214282320  773840905c424a10a4a31aba9d6458bb|__g1114a30c6e

But I get as below

   Unnamed: 0  ...                                              CT ID
0            0  ...  x1E5e3ukRyEFRT6SUAF6lg|d543d3d064da465b8576d87
1            1  ...  aa0d2dac654d4154bf7c09f73faeaf62|-vf6738ee3bed
2            2  ...  6FfHZRoiWs2VO02Pruk07A|__g3d877adf9d154637be26
3            3  ...  54e2c39cd35044ffbd9c0918d07923dc|__gbe204670ca
4            4  ...  __g1114a30c6ea548a2a83d5a51718ff0fd|773840905c
5            5  ...  9e6eb976075b4b189ae7dde42b67ca3d|WgpKucd28IcdE

IM NO columns header name and its value should be 20 digit encrpted , Normally encryption is done as below

import pyffx
strEncrypt = pyffx.Integer(b'dkrya@Jppl1994', length=20)
strEncrptVal = strEncrypt.encrypt(int('9digit IM No'))

ct_data.iloc[:, 1]) displays below thing

0     214281340
1     214281244
2     175326863
3     299631931
4     214282320
5     214279026

Solution

  • This should be a comment but it contains formatted data.

    It is probably a mere display problem. With the initial sample of you dataframe, I have executed your command and printed its returned values:

    print(ct_data['IM NO'].apply(lambda x: pyffx.Integer(b'dkrya@Jppl1994', length=20).encrypt(int(x))))
    
    0    88741194526272080902
    1     2665012251053580165
    2    18983388112345132770
    3    85666027666173191357
    4    78253063863998100367
    Name: IM NO, dtype: object
    

    So it is correctly executed. Let us go one step further:

    ct_data['IM NO'] = ct_data['IM NO'].apply(lambda x: pyffx.Integer(b'dkrya@Jppl1994', length=20).encrypt(int(x)))
    print(ct_data['IM NO'])
    
    0    88741194526272080902
    1     2665012251053580165
    2    18983388112345132770
    3    85666027666173191357
    4    78253063863998100367
    Name: IM NO, dtype: object
    

    Again...

    That means that your command was successfull, but as the IM NO column is now larger, you system can no more display all the columns and it displays the first and las ones, with ellipses (...) in the middle.