【发布时间】:2017-11-16 05:01:03
【问题描述】:
请仔细阅读代码,我在其中提到了问题。
import numpy as np
import pandas as pd
print("hello")
data = np.array([['', 'Col1', 'Col2'], ['Row1', 1, 2], ['Row2', 3, 4]])
df = pd.DataFrame(data=data[1:, 1:], columns=data[0, 1:])
print(df)
df_to_records = df.to_records(index=False)
records_to_bytes = df_to_records.tobytes()
'''
encryption, decryption code here using cryptography.fernet . It takes bytes
as input and gives bytes as output.
'''
# How can I retrieve DataFrame from records_to_bytes. I can easily retrieve
# from df_to_records
df_retrieved = pd.DataFrame.from_records(df_to_records)
# What I need is
# df_retrieved = pd.DataFrame.from_records("Inverse operation of
# df_to_records.tobytes()")
print(df_retrieved)
只要能达到目的,任何替代方法都会受到赞赏: 创建 pandas 框架 --> 将其转换为字节(cryptography.Fernet 将 bytearray 作为输入)。 --> 加密。解密并取回 DataFrame。
【问题讨论】:
标签: python python-3.x pandas numpy scipy