为了账号安全,请及时绑定邮箱和手机立即绑定

熊猫使用 tldextract 加入单元格中的最后 2 个昏迷分隔项

熊猫使用 tldextract 加入单元格中的最后 2 个昏迷分隔项

qq_花开花谢_0 2021-09-14 15:23:59
我有一个 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
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 188 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号