Q:

Pandas is sorting integer in a wierd way like string

Even when a column in a pandas df is int.. It is being sorted like a string or in a weird way.
n_frames  video        img
-----------------------------
1         Videos482    1.jpg
10        Videos482    2g.jpg
11        Videos482    2d.jpg
2         Videos482    1q.jpg
1         Videos484    234.jpg
100       Videos484    34.jpg

What I want is: See the n_frames column.
n_frames  video        img
-----------------------------
1         Videos482    1.jpg
2         Videos482    1t.jpg
10        Videos482    2g.jpg
11        Videos482    1q.jpg
1         Videos484    234.jpg
100       Videos484    34.jpg

When I check df.dtypes I get: 
n_frames   int32

My code:
print(df.dtypes)
df = df.groupby('video')
df.apply(lambda _df: _df.sort_values(by=['n_frames']))
df.apply(lambda _df: _df.to_csv("rubbish.csv", index=False ))

So basically. I want to groupby the video keeping the n_frames in increasing accending order.
Upper data is small form of original.
Original>
n_frames,trainTest,classes,vdo_noext,img
1,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 1.jpg
10,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 10.jpg
100,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 100.jpg
101,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 101.jpg
102,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 102.jpg
103,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 103.jpg
104,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 104.jpg
105,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 105.jpg
106,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 106.jpg
107,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 107.jpg
108,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 108.jpg
109,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 109.jpg
11,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 11.jpg
110,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 110.jpg
111,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 111.jpg
112,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 112.jpg
113,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 113.jpg
114,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 114.jpg
115,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 115.jpg
116,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 116.jpg
117,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 117.jpg
118,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 118.jpg
119,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 119.jpg
12,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 12.jpg
120,1,1,train/Normal/Normal_Videos482_x264,train/Normal/Normal_Videos482_x264@ 120.jpg

Update: n_frames column dtype was never a string and integer even before I converted into int..
Why is integer being sorted in that wierd way?

A:

Difficult to say without the data to hand but I would switch the rows around like so:
df = df.groupby('video')
df['n_frames'] = df['n_frames'].astype(int)
df.apply(lambda _df: _df.sort_values(by=['n_frames']))
df.apply(lambda _df: _df.to_csv("rubbish.csv", index=False ))

In other words, change the data type after the groupby

