首页 > 解决方案 > 提取具有点拆分的列的倒数第二个项目

问题描述

我在数据框中有以下列:

  `'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 rowFunctionalInterfaceTest`在第六个)

标签: pythonpandassplit

解决方案


IIUC 用途:

df['new'] = df['col'].str.split('\.').str[-2]

推荐阅读