python - 提取具有点拆分的列的倒数第二个项目
问题描述
我在数据框中有以下列:
`'org.eclipse.collections.impl.jmh.LongIntMapTest.copyTest'
'org.eclipse.collections.impl.jmh.LongIntMapTest.get'
'org.eclipse.collections.impl.jmh.LongIntMapTest.preizedPut'
'org.eclipse.collections.impl.jmh.LongIntMapTest.put'
'org.eclipse.collections.impl.jmh.LongIntMapTest.remove'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.parallel_eager_ec'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.parallel_eager_ec_hand_coded'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.parallel_lazy_ec'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.parallel_lazy_ec_hand_coded'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.parallel_lazy_jdk'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.parallel_lazy_scala'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.parallel_lazy_scala_hand_coded'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.serial_eager_ec'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.serial_eager_ec_hand_coded'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.serial_eager_scala'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.serial_lazy_ec'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.serial_lazy_jdk'
'org.eclipse.collections.impl.jmh.FunctionalInterfaceTest.serial_lazy_scala'`
正如我们看到的长度不同,我想在名为类的数据框中添加一个新列,该列包含名称的倒数第二部分。所有值都用点分隔。所以预期的输出将是一个有 2 列的数据框,第一个是 Benchmark(附在这篇文章中的那个),第二个是 Class(基准值中倒数第二个项目,如'org. eclipse.collections.impl.jmh.LongIntMapTest
in the first row
FunctionalInterfaceTest`在第六个)
解决方案
IIUC 用途:
df['new'] = df['col'].str.split('\.').str[-2]
推荐阅读
- javascript - 单击 HTML 表格中的下拉链接时如何动态调用页面?
- c# - 如果添加 Sytem.Net.Http DLL 作为代码参考,则断点在脚本组件中不起作用
- sql - 如何将 SQL Pivot Null 结果屏蔽为零
- excel - 调用位于另一个模块的用户表单中的 Private Sub CommandButton1_Click()?
- angular - 如何在 Angular 6 Web 应用程序中使用打字稿防止 f12 和打印屏幕键
- angular - Angular 7无法包含自定义打字稿定义文件
- java - Java:如何将 com.google.api.services.drive.model.File 转换为 InputStream?
- php - Facebook 广告 API:ID 为“**********************”的对象不存在,由于缺少权限而无法加载
- python - 正则表达式匹配括号中的所有数字,但不匹配单词中的数字
- javascript - Vuetify 中是否有特定的数字输入组件?