擅长:python、mysql、java
<p>我想你需要<a href="http://pandas.pydata.org/pandas-docs/stable/timedeltas.html" rel="nofollow noreferrer">^{<cd1>}</a>s:</p>
<pre><code>#remove NaNs rows in time column if necessary
#df = df.dropna(subset=['time'])
#or replace NaNs to 0
#df['time1'] = df['time1'].fillna(0)
#convert to int, then str and add 0
s = df['time'].astype(int).astype(str).str.zfill(4)
#add : twice
df['time1'] = s.str[:2] + ':' + s.str[2:] + ':00'
#convert to timedeltas
df['time2'] = pd.to_timedelta(df['time1'])
print (df)
bus_no time time1 time2
0 Bus1 2.0 00:02:00 00:02:00
1 Bus2 840.0 08:40:00 08:40:00
2 Bus3 2340.0 23:40:00 23:40:00
3 Bus4 15.0 00:15:00 00:15:00
4 Bus5 1205.0 12:05:00 12:05:00
5 Bus6 1304.0 13:04:00 13:04:00
6 Bus7 1620.0 16:20:00 16:20:00
7 Bus8 9.0 00:09:00 00:09:00
</code></pre>