Having formatted your data in order to make a MCVE:
import pandas as pd
data = {
'smonth': ['Apr', 'Jan', 'Jul', 'Oct']
,'temp': [61, 32, 69, 43]
}
df = pd.DataFrame(data)
We have the following DataFrame:
smonth temp
0 Apr 61
1 Jan 32
2 Jul 69
3 Oct 43
Now we convert your String Month (using %b
formatter, see list) column into a Date, then into an Index and we finally extract Month field:
df['month'] = pd.DatetimeIndex(pd.to_datetime(df['smonth'], format='%b')).month
Then reindex and sort:
df = df.set_index('month').sort_index()
It is done:
smonth temp
month
1 Jan 32
4 Apr 61
7 Jul 69
10 Oct 43
Update
If I explicitly reproduce your input, using:
df2 = pd.DataFrame(
data['temp']
,index=pd.Index(data['smonth'], name='Month')
,columns=['Temp']
)
Then it reduces to:
df2.index = pd.to_datetime(df2.index, format='%b').month
df2.sort_index(inplace=True)
And returns:
Temp
Month
1 32
4 61
7 69
10 43