I have a pandas dataframe that I want to sort by one of the columns. Problem is, the data that needs to be sorted looks like this: "'Number 1' - Specimen 'Number 2'". I want to sort by 'Number 1' first, and then 'Number 2'.
An example:
import pandas as pd
df = pd.DataFrame({'Name': ['12001 - Specimen 10', '12000 - Specimen 1', '12000 - Specimen 10',
'12000 - Specimen 2', '12000 - Specimen 5', '12001 - Specimen 1',
'12001 - Specimen 2'],
'Results': [2, 4, 2, 3, 10, 8, 2]})
df.sort_values('Name')
Name Results
1 12000 - Specimen 1 4
2 12000 - Specimen 10 2
3 12000 - Specimen 2 3
4 12000 - Specimen 5 10
5 12001 - Specimen 1 8
0 12001 - Specimen 10 2
6 12001 - Specimen 2 2
This correctly sorts by the first number, but for the seconds number it puts 10 before 2.
I have seen two similar questions being posted, but in those cases they had the numbers and strings separated by an '_', and the answers suggested splitting them before sorting. I tried doing something similar, but it ended up only sorting by the second number.
sort dataFrame index containing string and number
Sort DataFrame index that has a string and number
If possible, I would prefer something that can be done purely in pandas with no other packages needed.