3-订单持续时间的计算

import pandas as pd
taxiod = pd.read_csv(r'data-sample/TaxiOD.csv',header=None)
taxiod.columns=['VehicleNum','Stime','SLng','SLat','ELng','ELat','Etime']
taxiod
C:\Program Files (x86)\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:3146: DtypeWarning: Columns (0,2,3,4,5) have mixed types.Specify dtype option on import or set low_memory=False.

  has_raised = await self.run_ast_nodes(code_ast.body, cell_name,

VehicleNumStimeSLngSLatELngELatEtime0VehicleNumStimeSLngSLatELngELatEtime12222300:03:23114.1674649999999922.562468114.2252350000000122.5527500:10:4822222300:11:33114.2271522.554167114.2292179999999922.56021700:15:1932222300:17:13114.2313540000000122.562166114.25579822.59096700000000300:29:0642222300:36:45114.24019622.56365114.11996522.56666800:54:42……………………4647143694722:39:12114.00622.5481113.99622.537122:46:254647153694722:49:38113.99522.535113.92222.496523:13:154647163694723:24:24113.92122.5135113.9322.494223:30:324647173694723:37:09113.92822.5126113.91122.487923:49:104647183694723:52:18113.9122.4876NaNNaNNaN

464719 rows × 7 columns

taxiod=taxiod.drop([0])
taxiod.index = range(len(taxiod))
taxiod

VehicleNumStimeSLngSLatELngELatEtime02222300:03:23114.1674649999999922.562468114.2252350000000122.5527500:10:4812222300:11:33114.2271522.554167114.2292179999999922.56021700:15:1922222300:17:13114.2313540000000122.562166114.25579822.59096700000000300:29:0632222300:36:45114.24019622.56365114.11996522.56666800:54:4242222301:01:14114.1354139999999822.575933114.16674822.60826701:08:17……………………4647133694722:39:12114.00622.5481113.99622.537122:46:254647143694722:49:38113.99522.535113.92222.496523:13:154647153694723:24:24113.92122.5135113.9322.494223:30:324647163694723:37:09113.92822.5126113.91122.487923:49:104647173694723:52:18113.9122.4876NaNNaNNaN

464718 rows × 7 columns

taxiod=taxiod[-taxiod['ELng'].isnull()]
tmp= pd.to_datetime(taxiod['Stime'])
tmp
0        2021-03-03 00:03:23
1        2021-03-03 00:11:33
2        2021-03-03 00:17:13
3        2021-03-03 00:36:45
4        2021-03-03 01:01:14
                 ...

464712   2021-03-03 22:08:22
464713   2021-03-03 22:39:12
464714   2021-03-03 22:49:38
464715   2021-03-03 23:24:24
464716   2021-03-03 23:37:09
Name: Stime, Length: 464717, dtype: datetime64[ns]
tmp1=pd.to_datetime(taxiod['Etime'])
tmp1
0        2021-03-03 00:10:48
1        2021-03-03 00:15:19
2        2021-03-03 00:29:06
3        2021-03-03 00:54:42
4        2021-03-03 01:08:17
                 ...

464712   2021-03-03 22:36:53
464713   2021-03-03 22:46:25
464714   2021-03-03 23:13:15
464715   2021-03-03 23:30:32
464716   2021-03-03 23:49:10
Name: Etime, Length: 464717, dtype: datetime64[ns]
Duration=tmp1-tmp
Duration
taxiod['Duration']=Duration
taxiod
<ipython-input-10-8b258a85ed6d>:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.

Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  taxiod['Duration']=Duration
</ipython-input-10-8b258a85ed6d>

VehicleNumStimeSLngSLatELngELatEtimeDuration02222300:03:23114.1674649999999922.562468114.2252350000000122.5527500:10:480 days 00:07:2512222300:11:33114.2271522.554167114.2292179999999922.56021700:15:190 days 00:03:4622222300:17:13114.2313540000000122.562166114.25579822.59096700000000300:29:060 days 00:11:5332222300:36:45114.24019622.56365114.11996522.56666800:54:420 days 00:17:5742222301:01:14114.1354139999999822.575933114.16674822.60826701:08:170 days 00:07:03………………………4647123694722:08:22113.91422.5314113.99722.545622:36:530 days 00:28:314647133694722:39:12114.00622.5481113.99622.537122:46:250 days 00:07:134647143694722:49:38113.99522.535113.92222.496523:13:150 days 00:23:374647153694723:24:24113.92122.5135113.9322.494223:30:320 days 00:06:084647163694723:37:09113.92822.5126113.91122.487923:49:100 days 00:12:01

464717 rows × 8 columns

taxiod.rename(columns={'duration': 'Duration'}, inplace=True)
C:\Program Files (x86)\Anaconda3\lib\site-packages\pandas\core\frame.py:4296: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  return super().rename(
taxiod

VehicleNumStimeSLngSLatELngELatEtimeDuration02222300:03:23114.1674649999999922.562468114.2252350000000122.5527500:10:480 days 00:07:2512222300:11:33114.2271522.554167114.2292179999999922.56021700:15:190 days 00:03:4622222300:17:13114.2313540000000122.562166114.25579822.59096700000000300:29:060 days 00:11:5332222300:36:45114.24019622.56365114.11996522.56666800:54:420 days 00:17:5742222301:01:14114.1354139999999822.575933114.16674822.60826701:08:170 days 00:07:03………………………4647123694722:08:22113.91422.5314113.99722.545622:36:530 days 00:28:314647133694722:39:12114.00622.5481113.99622.537122:46:250 days 00:07:134647143694722:49:38113.99522.535113.92222.496523:13:150 days 00:23:374647153694723:24:24113.92122.5135113.9322.494223:30:320 days 00:06:084647163694723:37:09113.92822.5126113.91122.487923:49:100 days 00:12:01

464717 rows × 8 columns

r=taxiod['Duration'].iloc[0]
taxiod['order_time']=taxiod['Duration'].apply(lambda r:r.seconds)
<ipython-input-13-d23b5d7f6867>:2: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.

Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  taxiod['order_time']=taxiod['Duration'].apply(lambda r:r.seconds)
</ipython-input-13-d23b5d7f6867>
taxiod.drop(columns=['Duration'])

VehicleNumStimeSLngSLatELngELatEtimeorder_time02222300:03:23114.1674649999999922.562468114.2252350000000122.5527500:10:4844512222300:11:33114.2271522.554167114.2292179999999922.56021700:15:1922622222300:17:13114.2313540000000122.562166114.25579822.59096700000000300:29:0671332222300:36:45114.24019622.56365114.11996522.56666800:54:42107742222301:01:14114.1354139999999822.575933114.16674822.60826701:08:17423………………………4647123694722:08:22113.91422.5314113.99722.545622:36:5317114647133694722:39:12114.00622.5481113.99622.537122:46:254334647143694722:49:38113.99522.535113.92222.496523:13:1514174647153694723:24:24113.92122.5135113.9322.494223:30:323684647163694723:37:09113.92822.5126113.91122.487923:49:10721

464717 rows × 8 columns

taxiod['hour']=taxiod['Stime'].apply(lambda r:r.split(':')[0])
taxiod
<ipython-input-15-c7c6b55b9ff2>:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.

Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  taxiod['hour']=taxiod['Stime'].apply(lambda r:r.split(':')[0])
</ipython-input-15-c7c6b55b9ff2>

VehicleNumStimeSLngSLatELngELatEtimeDurationorder_timehour02222300:03:23114.1674649999999922.562468114.2252350000000122.5527500:10:480 days 00:07:254450012222300:11:33114.2271522.554167114.2292179999999922.56021700:15:190 days 00:03:462260022222300:17:13114.2313540000000122.562166114.25579822.59096700000000300:29:060 days 00:11:537130032222300:36:45114.24019622.56365114.11996522.56666800:54:420 days 00:17:5710770042222301:01:14114.1354139999999822.575933114.16674822.60826701:08:170 days 00:07:0342301……………………………4647123694722:08:22113.91422.5314113.99722.545622:36:530 days 00:28:311711224647133694722:39:12114.00622.5481113.99622.537122:46:250 days 00:07:13433224647143694722:49:38113.99522.535113.92222.496523:13:150 days 00:23:371417224647153694723:24:24113.92122.5135113.9322.494223:30:320 days 00:06:08368234647163694723:37:09113.92822.5126113.91122.487923:49:100 days 00:12:0172123

464717 rows × 10 columns

import matplotlib.pyplot as plt
fig  =plt.figure(1,(7,3),dpi=250)
ax   =plt.subplot(111)
plt.sca(ax)

plt.boxplot(taxiod['order_time']/60)
plt.ylabel('minutes')
plt.xlabel('order time')
plt.ylim(0,60)

plt.show()


3-订单持续时间的计算
import matplotlib.pyplot as plt
fig     = plt.figure(1,(10,5),dpi = 250)
ax      = plt.subplot(111)
plt.sca(ax)

hour = taxiod['hour'].drop_duplicates().sort_values()
datas = []
for i in range(len(hour)):
    datas.append(taxiod[taxiod['hour']==hour.iloc[i]]['order_time']/60)

plt.boxplot(datas)

plt.xticks(range(1,len(hour)+1),list(hour))

plt.ylabel('Order time(minutes)')
plt.xlabel('Order start time')
plt.ylim(0,60)

plt.show()


3-订单持续时间的计算

import seaborn as sns
fig     = plt.figure(1,(10,5),dpi = 250)
ax      = plt.subplot(111)
plt.sca(ax)

sns.boxplot(x='hour',y=taxiod['order_time']/60,data=taxiod,ax=ax)

plt.ylabel('order_time(minutes)')
plt.xlabel('order start time')
plt.ylim(0,(60))
plt.show()


3-订单持续时间的计算

Original: https://blog.csdn.net/weixin_44676579/article/details/112974077
Author: code_Wang910
Title: 3-订单持续时间的计算

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/756678/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球