1.str -> base64
# -*- coding: utf-8 -*-
import base64
base64_str = base64.b64encode(my_str.encode('utf-8'))
2. base64->str
# -*- coding: utf-8 -*-
my_str = base64.b64decode(base64_str).decode('utf-8')
3.其他
pandas数据转json再转base64
def df_to_base64(df):
df_json_str = df.to_json(orient = 'split')
df_json_dict = json.loads(df_json_str)
try:
del df_json_dict['index']
except:
print('trace_back: {}'.format(traceback.format_exc()))
pass
return base64.b64encode(json.dumps(df_json_dict).encode('utf-8'))
base64字符串转pandas数据
def base64_to_df(df_base64):
base64_byte = base64.b64decode(df_base64).decode('utf-8')
base64_dict = json.loads(base64_byte)
df = pd.DataFrame(data=base64_dict['data'],
columns=base64_dict['columns'],
index=None)
return df
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://hqyman.cn/post/4921.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
打赏微信支付宝扫一扫,打赏作者吧~
休息一下~~