我有一个 Pandas 数据框并且正在使用 tldextract 库。我在创建新列并连接第二个和第三个分隔的字符串时遇到问题。
#First 5 rows for testing purposes
df = pd.DataFrame(request['destinationhostname'].iloc[0:5])
destinationhostname
0 pod51042psh.outlook.com
1 s.mrmserve.com
2 client-office365-tas.msedge.net
3 otf.msn.com
4 log.pinterest.com
#Applying tld extract on destinationhostname column
df['req'] = request.destinationhostname.apply(tldextract.extract)
destinationhostname req
0 pod51042psh.outlook.com (pod51042psh, outlook, com)
1 s.mrmserve.com (s, mrmserve, com)
2 client-office365-tas.msedge.net (client-office365-tas, msedge, net)
3 otf.msn.com (otf, msn, com)
4 log.pinterest.com (log, pinterest, com)
我已经尝试以多种方式执行下一部分,如下所示,但不断出现错误。
df['fld'] = df['req'].apply('.'.join[1:3])
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
或者
TypeError: sequence item 0: expected string, ExtractResult found
我想要的输出是:
destinationhostname req fld
0 pod51042psh.outlook.com (pod51042psh, outlook, com) outlook.com
1 s.mrmserve.com (s, mrmserve, com) mrmserve.com
2 client-office365-tas.msedge.net (client-office365-tas, msedge, net) msedge.net
3 otf.msn.com (otf, msn, com) msn.com
4 log.pinterest.com (log, pinterest, com) pinterest.com
相关分类