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

Python Pandas-将子字符串从一列复制到另一列

Python Pandas-将子字符串从一列复制到另一列

暮色呼如 2021-04-04 12:13:49
我有以下数据框<style type="text/css">.tg  {border-collapse:collapse;border-spacing:0;}.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}.tg .tg-baqh{text-align:center;vertical-align:top}.tg .tg-9hbo{font-weight:bold;vertical-align:top}.tg .tg-yw4l{vertical-align:top}</style><table class="tg">  <tr>    <th class="tg-9hbo">JobID</th>    <th class="tg-9hbo">JobName</th>    <th class="tg-9hbo">JobLink</th>  </tr>  <tr>    <td class="tg-baqh">n/a</td>    <td class="tg-baqh">Some job name</td>    <td class="tg-yw4l">https://www.particulawebsite.com/jobs-some-job-name.id123465789</td>  </tr>  <tr>    <td class="tg-baqh">n/a</td>    <td class="tg-baqh">another job name</td>    <td class="tg-yw4l">https://www.particulawebsite.com/jobs-another-job-name.id987654321</td>  </tr>  <tr>    <td class="tg-baqh">n/a</td>    <td class="tg-baqh">yet another name</td>    <td class="tg-yw4l">https://www.particulawebsite.com/jobs-yet-another-job-name.id987321654</td>  </tr></table>我要做的是从JobLink列中复制id部分,并将其放在JobID中。到目前为止,尚未成功完成此操作,因此是我的问题。
查看完整描述

2 回答

?
温温酱

TA贡献1752条经验 获得超4个赞

希望这可以帮助!

df['JobID'] = df['JobLink'].map(lambda x: x.split('.')[-1])

这会将“ JobID”的第一行存储为“ id123465789”


查看完整回答
反对 回复 2021-04-13
  • 2 回答
  • 0 关注
  • 481 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

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

帮助反馈 APP下载

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

公众号

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