<p>您可以使用由<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.apply.html" rel="nofollow noreferrer">^{<cd1>}</a>对pandas实现的<a href="https://stackoverflow.com/a/21754610">this solution</a>:</p>
<pre><code>from Crypto.Cipher import XOR
import base64
def encrypt(key, plaintext):
cipher = XOR.new(key)
return base64.b64encode(cipher.encrypt(plaintext))
def decrypt(key, ciphertext):
cipher = XOR.new(key)
return cipher.decrypt(base64.b64decode(ciphertext))
load['Encoded_Column'] = load['F'].apply(lambda x: encrypt('password',x))
load['Decoded_Column'] = (load['Encoded_Column'].apply(lambda x: decrypt('password', x))
.str.decode("utf-8"))
print (load)
A B C D E F Encoded_Column Decoded_Column
0 a 4 7 1 5 a b'EQ==' a
1 b 5 8 3 3 a b'EQ==' a
2 c 4 9 5 6 a b'EQ==' a
3 d 5 4 4 9 b b'Eg==' b
4 e 5 2 2 2 b b'Eg==' b
5 f 4 0 0 4 b b'Eg==' b
</code></pre>
<p>另一个<a href="https://stackoverflow.com/a/38223403">solution</a>:</p>
^{pr2}$
<p>或使用<code>list comprehension</code>:</p>
<pre><code>load['Encoded_Column'] = [encode('password',x) for x in load['F']]
load['Decoded_Column'] = [decode('password', x) for x in load['Encoded_Column']]
print (load)
A B C D E F Encoded_Column Decoded_Column
0 a 4 7 1 5 a w5E= a
1 b 5 8 3 3 a w5E= a
2 c 4 9 5 6 a w5E= a
3 d 5 4 4 9 b w5I= b
4 e 5 2 2 2 b w5I= b
5 f 4 0 0 4 b w5I= b
</code></pre>