数据框架构如下
root
|-- name: string (nullable = true)
|-- address_info: string (nullable = true)
示例内容或address_info栏如下
{[email protected], fqdn=sparp.org, domain=sharp, host=sharp.org, subdomain=, alias=, addr=test, tld=org, [email protected]}
尝试使用 from_json 并使用自定义架构来匹配 address_info 转换为 json,但没有成功。
所需的数据帧输出如下:
name original_email fqdn domain
XXX [email protected] sparp.org sharp
尝试通过使用自定义架构来匹配address_info,使用from_json将字符串类型列转换为json,但没有成功。
数据帧的预期输出:
name original_email fqdn domain
XXX [email protected] sparp.org sharp
假设您的地址信息字符串如下:
address_info ='{"original_email"="[email protected]", "fqdn"="sparp.org", "domain"="sharp", "host"="sharp.org"}'
将所有
'='
替换为':'
,使其成为字典
address_info = address_info.replace('=',':')
#'{"original_email"="[email protected]", "fqdn"="sparp.org", "domain"="sharp", "host"="sharp.org"}'
现在,导入
ast
模块:
import ast
d = ast.literal_eval(address_info)
print(d)
#输出
{'original_email': '[email protected]',
'fqdn': 'sparp.org',
'domain': 'sharp',
'host': 'sharp.org'}