Peter
Peter

Reputation: 155

extract the second to last item for column with dot splitting

I have the following columns in data frame:

  `'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'` 

As we can see the length is different, I want to add a new column to the data frame named as a class, this column contains the second to last part of the name. all the values are separated by dot. So the expected output will be a dataframe with 2 columns, the first one is the Benchmark(the one that attached in this post), and the second one is the Class (the second to last item in the values of Benchmark like 'org.eclipse.collections.impl.jmh.LongIntMapTestin the first rowFunctionalInterfaceTest` in the sixth one )

Upvotes: 0

Views: 27

Answers (1)

jezrael
jezrael

Reputation: 862511

IIUC use:

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

Upvotes: 1

Related Questions