Skip to content
Advertisement

Python – Get Last Element after str.split()

I use pandas and I have data and the data look like this

JavaScript

Then I split it based on ‘space’ using str.split()

So the data will look like this in DataFrame

JavaScript

How to take the StudentID for every students only and save it in new column?

Advertisement

Answer

Use a list comprehension to take the last element of each of the split strings:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement