Issue
I use pandas and I have data and the data look like this
FirstName LastName StudentID
FirstName2 LastName2 StudentID2
Then I split it based on 'space' using str.split()
So the data will look like this in DataFrame
[[FirstName, LastName, StudentID],
[FirstName2, LastName2, StudentID2]]
How to take the StudentID for every students only and save it in new column?
Solution
Use a list comprehension to take the last element of each of the split strings:
ids = [val[-1] for val in your_string.split()]
Answered By - Tim
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.