我有一个 Pandas 数据框并且正在使用 tldextract 库。我在创建新列并连接第二个和第三个分隔的字符串时遇到问题。#First 5 rows for testing purposesdf = pd.DataFrame(request['destinationhostname'].iloc[0:5]) destinationhostname0 pod51042psh.outlook.com1 s.mrmserve.com2 client-office365-tas.msedge.net3 otf.msn.com4 log.pinterest.com#Applying tld extract on destinationhostname columndf['req'] = request.destinationhostname.apply(tldextract.extract) destinationhostname req0 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 fld0 pod51042psh.outlook.com (pod51042psh, outlook, com) outlook.com1 s.mrmserve.com (s, mrmserve, com) mrmserve.com2 client-office365-tas.msedge.net (client-office365-tas, msedge, net) msedge.net3 otf.msn.com (otf, msn, com) msn.com4 log.pinterest.com (log, pinterest, com) pinterest.com
添加回答
举报
0/150
提交
取消