<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohan Rajput on Medium]]></title>
        <description><![CDATA[Stories by Mohan Rajput on Medium]]></description>
        <link>https://medium.com/@rajputmohan033?source=rss-2423e2a0a5fa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uc-C_wExaREuudslD1y7Iw.jpeg</url>
            <title>Stories by Mohan Rajput on Medium</title>
            <link>https://medium.com/@rajputmohan033?source=rss-2423e2a0a5fa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 06:00:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajputmohan033/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Food Delivery Time Analysis]]></title>
            <link>https://medium.com/enjoy-algorithm/food-delivery-time-analysis-4c9700316b08?source=rss-2423e2a0a5fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c9700316b08</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[food-delivery]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Mohan Rajput]]></dc:creator>
            <pubDate>Sun, 25 May 2025 04:32:07 GMT</pubDate>
            <atom:updated>2025-05-25T04:32:07.267Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vr1o2LgLW3zLugZTNoJSgw.jpeg" /></figure><h4><strong>Introduction</strong></h4><p>The rapidly expanding food delivery industry is projected to reach a revenue of <a href="https://www.statista.com/outlook/emo/online-food-delivery/india">US$ 54.97 billion in 2025</a>. The number of users is expected to rise to 363.4 million in the food delivery market by 2030. In such a highly competitive market, delivery time plays a crucial role in determining a company’s growth and customer satisfaction.</p><p>We’ve all experienced that our hunger increases exponentially with time after placing an order, and the only thing we can focus on is where our delivery person is. So, it is essential to understand what factors affect delivery time. This blog aims to analyze those factors using Data Analysis techniques on a popular dataset.</p><p><strong>Questions to be answered..</strong></p><ol><li>What is the average delivery time, and its distribution?</li><li>Does the type of vehicle affect the delivery time?</li><li>How does the age of the delivery person influence delivery time?</li><li>What is the optimal age group that will be most efficient for the delivery person role?</li><li>Which combination of features in the dataset offers the quickest food delivery?</li></ol><h4><strong>Overview</strong></h4><p>For our delivery time analysis, we must have some essential features like the type of vehicle any delivery person is using, the age of the delivery person, the distance to be covered, etc. We use an open-source dataset, “<a href="https://www.kaggle.com/datasets/rajatkumar30/food-delivery-time">Food delivery time</a>” from Kaggle, which contains some meaningful features.</p><p>Dataset features are as follows:</p><pre>Index([&#39;ID&#39;, &#39;Delivery_person_ID&#39;, &#39;Delivery_person_Age&#39;,<br>       &#39;Delivery_person_Ratings&#39;, &#39;Restaurant_latitude&#39;,<br>       &#39;Restaurant_longitude&#39;, &#39;Delivery_location_latitude&#39;,<br>       &#39;Delivery_location_longitude&#39;, &#39;Type_of_order&#39;, &#39;Type_of_vehicle&#39;,<br>       &#39;Time_taken(min)&#39;],<br>      dtype=&#39;object&#39;)</pre><p>As several datasets related to this are available in the market, some of them have irrelevant extra features like the marital status of a delivery person, which shouldn’t affect the delivery time. Should it? And some of them lack essential features like the type of vehicle and the age of a delivery person. Let’s uncover some of these facts: &quot;Data doesn’t lie!”</p><p>Using Python libraries like Pandas, Numpy, Matplotlib, Seaborn, etc. We will uncover the patterns and try to understand the data through visualisation.</p><h3><strong>Analysis</strong></h3><h4><strong>Exploratory Data Analysis</strong>: Summary Statistics &amp; Delivery Time Distribution</h4><p>First, we will examine the summary statistics of all the columns. Summary statistics (mean, median, min, max, and quartiles) will help us to get an idea of the quality of a feature.</p><pre>print(&quot;\nSummary statistics for numeric columns:&quot;)<br>print(df.describe())</pre><pre>Summary statistics for numeric columns:<br>       Delivery_person_Age  Delivery_person_Ratings  Restaurant_latitude  \<br>count         45593.000000             45593.000000         45593.000000   <br>mean             29.544075                 4.632367            17.017729   <br>std               5.696793                 0.327708             8.185109   <br>min              15.000000                 1.000000           -30.905562   <br>25%              25.000000                 4.600000            12.933284   <br>50%              29.000000                 4.700000            18.546947   <br>75%              34.000000                 4.800000            22.728163   <br>max              50.000000                 6.000000            30.914057   <br><br>       Restaurant_longitude  Delivery_location_latitude  \<br>count          45593.000000                45593.000000   <br>mean              70.231332                   17.465186   <br>std               22.883647                    7.335122   <br>min              -88.366217                    0.010000   <br>25%               73.170000                   12.988453   <br>50%               75.898497                   18.633934   <br>75%               78.044095                   22.785049   <br>max               88.433452                   31.054057   <br><br>       Delivery_location_longitude  Time_taken(min)  <br>count                 45593.000000     45593.000000  <br>mean                     70.845702        26.294607  <br>std                      21.118812         9.383806  <br>min                       0.010000        10.000000  <br>25%                      73.280000        19.000000  <br>50%                      76.002574        26.000000  <br>75%                      78.107044        32.000000  <br>max                      88.563452        54.000000  </pre><p>As we can see, some minor outliers in Ratings show a rating of 6 out of 5; we will drop these rows to maintain data quality, because a person couldn’t get a rating of 6 even if they deliver the food with restaurant-level presentation.</p><h4>Delivery time data distribution</h4><p>Now we will look at the time distribution, as it will provide some insights into how much a person should typically wait after ordering their food:</p><pre># Mean of delivery time<br>avg_time = df[&#39;Time_taken(min)&#39;].mean()<br>print(&quot;Average delivery time (min):&quot;, avg_time)<br><br># Mode of delivery time<br>mode_time = df[&#39;Time_taken(min)&#39;].mode()<br>print(&quot;Mode of Time Taken (min):&quot;)<br>print(mode_time)<br><br># Plotting time distribution<br>plt.figure(figsize=(8,5))<br>sns.histplot(df[&#39;Time_taken(min)&#39;], bins=30, kde=True)<br>plt.title(&quot;Distribution of Delivery Time (min)&quot;)<br>plt.xlabel(&quot;Time Taken (minutes)&quot;)<br>plt.ylabel(&quot;Frequency&quot;)<br>plt.show()</pre><pre>Average delivery time (min): 26.29460662821047<br>Mode of Time Taken (min): 26</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pS2fNqzG1Fs-vUrT2lJtww.png" /></figure><p>As we can see, the mean delivery time is 26.3 minutes, and the mode is 26 minutes, which shows that the delivery service is generally efficient, as most orders are delivered within half an hour. Mean and median are very close, suggesting a symmetrical/slightly skewed distribution, with no extreme outliers, as shown in the plotted bar graph above.</p><h4><strong>Calculating Delivery Distance: </strong>Using latitude and longitude</h4><p>The dataset gives the restaurant&#39;s particular delivery geographic coordinates (latitude and longitude) and the customer’s delivery location. Using the Haversine formula, we will calculate the distance between the restaurant and the delivery location from these coordinates, as we couldn’t show a hungry person the coordinates where your food reached.</p><p><strong>Haversine Formula: </strong>It is a mathematical equation used to determine the distance between two points on the surface of a sphere using latitude and longitude.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NQJShMmVUso6jM5CHCijdQ.png" /><figcaption>Haversine Formula</figcaption></figure><p>where d is the distance between two points,</p><p>r = radius of the earth(6371 km),</p><p>ϕ1,ϕ2 ​ are the latitudes of the two points,</p><p>λ1,λ2​ are the longitudes of the two points.</p><pre>def haversine(lat1, lon1, lat2, lon2):<br>    lat1, lon1, lat2, lon2 = map(np.radians, [lat1, lon1, lat2, lon2])<br><br>    dlat = lat2 - lat1<br>    dlon = lon2 - lon1<br><br>    a = np.sin(dlat/2)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2)**2<br>    c = 2 * np.arcsin(np.sqrt(a))<br><br>    R = 6371<br>    return c * R<br><br>df[&#39;Distance_km&#39;] = haversine(df[&#39;Restaurant_latitude&#39;], df[&#39;Restaurant_longitude&#39;],<br>                              df[&#39;Delivery_location_latitude&#39;], df[&#39;Delivery_location_longitude&#39;])<br><br># print(df[[&#39;Distance_km&#39;]].head())</pre><p>Dropping NULL and unrealistic large distances, as we can not expect a bicycle or scooter guy to deliver the food to a place with more than 100 km, seems like a person living in the US ordering food from Canada:</p><pre>df = df.dropna()<br><br># dropping distances which are more than 100 km <br>df_clean = df[df[&#39;Distance_km&#39;] &lt; 100]</pre><h4><strong>Average Distance vs Vehicle Type:</strong></h4><p>After calculating the distance, we will check the mean average distance assigned to each type of vehicle, as we can’t expect a bicycle delivery person get assigned to a distance more than 15 km, Beacause if this happens that person will end up delivering only 2 to 3 orders at the end of the day.</p><pre># Ensure vehicle type strings are cleaned<br>df_clean[&#39;Type_of_vehicle&#39;] = df_clean[&#39;Type_of_vehicle&#39;].str.strip()<br><br># Grouping and calculate mean distance<br>avg_distance_by_vehicle = (<br>    df_clean.groupby(&#39;Type_of_vehicle&#39;)[&#39;Distance_km&#39;]<br>    .mean()<br>    .reset_index()<br>    .sort_values(by=&#39;Distance_km&#39;, ascending=False)<br>)<br><br>print(avg_distance_by_vehicle)</pre><pre>    Type_of_vehicle  Distance_km<br>0           scooter     9.773363<br>1  electric_scooter     9.748504<br>2        motorcycle     9.712078<br>3           bicycle     8.893599</pre><p>The average distance for bicycle persons is the lowest, as expected, at approximately 8.89 km, and can be covered in 30 to 35 minutes.</p><h4><strong>Delivery Time vs Vehicle Type:</strong></h4><p>Now we will analyze how vehicle impacts delivery time by plotting time vs vehicle type boxplot using matplotlib and seaborn libraries. <a href="https://medium.com/enjoy-algorithm/box-plot-using-python-data-summary-by-5-numbers-614a80bf2ba1">Box plot</a> gives the best idea for mean, max, min, and outliers (if there are any) for every type of vehicle.</p><pre>plt.figure(figsize=(8,5))<br>sns.boxplot(x=&#39;Type_of_vehicle&#39;, y=&#39;Time_taken(min)&#39;, data=df_clean)<br>plt.title(&quot;Delivery Time by Vehicle Type&quot;)<br>plt.xlabel(&quot;Vehicle Type&quot;)<br>plt.ylabel(&quot;Time Taken (minutes)&quot;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OYfQYhWZbgt0WwR3iwIAw.png" /><figcaption>Time Taken vs Vehicle Type Boxplot</figcaption></figure><p>From the boxplot analysis, we can see that motorcycles take the longest time, and scooters are the fastest, whether they are electric or manual. And there are very few minor outliers in manual and electric scooters.</p><p>Let’s quickly analyze their mean delivery time:</p><pre># Mean delivery time by vehicle type<br>mean_by_vehicle = (<br> df_clean<br> .groupby(&#39;Type_of_vehicle&#39;)[&#39;Time_taken(min)&#39;]<br> .mean()<br> .reset_index()<br> .rename(columns={&#39;Time_taken(min)&#39;: &#39;mean_time&#39;})<br>)<br><br>print(mean_by_vehicle)</pre><pre>  Type_of_vehicle   mean_time <br>0 bicycle           26.039216<br>1 electric_scooter  24.478400 <br>2 motorcycle        27.607372 <br>3 scooter           24.478876</pre><p>As with Boxplot, electric and manual scooters are the fastest, with an average delivery time of around 24 hours. In comparison, while motorcycles have the highest average time at 2. Bicycles fall in the middle, most likely because bicycle riders are assigned to short-range deliveries, as we previously analyzed their average distance, where high speed isn’t necessary, but maneuverability is an advantage.</p><h4><strong>Time vs Order Type:</strong></h4><p>The delivery time given in the dataset is from when the delivery person picks up the order from a restaurant. So, our delivery time should not vary much depending on the order type; a person takes the same time, whether it is an ice cream or a hot pizza.</p><pre># Mean delivery time (minutes) by order type<br>mean_time_by_order = (<br>    df_clean<br>        .groupby(&#39;Type_of_order&#39;)[&#39;Time_taken(min)&#39;]<br>        .mean()<br>        .reset_index()                                   <br>        .rename(columns={&#39;Time_taken(min)&#39;: &#39;mean_time&#39;})<br>        .sort_values(&#39;mean_time&#39;)                        <br>)<br><br>print(mean_time_by_order)</pre><pre> Type_of_order  mean_time<br>0       Drinks   26.193408<br>1        Snack   26.276076<br>2       Buffet   26.292297<br>3         Meal   26.429492</pre><p>As expected, the average delivery time for every order type (Drinks, Snacks, Buffet, and Meals) is very close (i.e., between 26 and 26.5 min), confirming that delivery time does not vary much with order type.</p><h4><strong>Time vs Age Group:</strong></h4><p>Now we will see whether the age of a delivery person can affect the delivery. We will create a new forum group by categorizing people into meaningful age groups.</p><pre>bins = [18, 25, 35, 45, 60]<br>labels = [&#39;18-25&#39;, &#39;26-35&#39;, &#39;36-45&#39;, &#39;46-60&#39;]<br>df_clean[&#39;Delivery_person_Age_Group&#39;] = pd.cut(df_clean[&#39;Delivery_person_Age&#39;], bins=bins, labels=labels)</pre><p>After grouping them, we will find out their mean time according to their respective age group:</p><pre><br>mean_time_by_age_group = (<br>    df_clean.groupby(&#39;Delivery_person_Age_Group&#39;)[&#39;Time_taken(min)&#39;]<br>    .mean()<br>    .reset_index()<br>    .rename(columns={&#39;Time_taken(min)&#39;: &#39;Mean_Delivery_Time&#39;})<br>)<br><br>print(&quot;Mean Delivery Time (min) by Age Group:&quot;)<br>print(mean_time_by_age_group)</pre><pre> Delivery_person_Age_Group   Mean_Delivery_Time<br>0                     18-25           22.969495<br>1                     26-35           26.935465<br>2                     36-45           29.490930<br>3                     46-60           24.677419</pre><p>The 18–25 age group has the fastest average delivery time (23 min), whereas the 36–45 age group takes the longest (29.5 min). This can be because younger individuals are more agile and faster on the road, while older age groups could be slower in navigation. This shows a moderate impact on delivery time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2bHxVfMc_hIB5b4MlBPhDw.png" /></figure><p>As we can see from the counterplot, the optimal age for a delivery person lies in the 18–25 age group.</p><h4><strong>Speed vs Age Group:</strong></h4><p>Now, let’s look at how people of different ages ride their vehicles by calculating their average speed; this will give us a sense of which age group may be at risk of accidents due to severe riding, as no one wants a quick delivery at the cost of someone’s safety.</p><pre># Speed in km/min<br>df_clean[&#39;Speed_km_per_min&#39;] = df_clean[&#39;Distance_km&#39;] / df_clean[&#39;Time_taken(min)&#39;]<br><br># Dropping rows with missing speed or age group<br>df_speed = df_clean.dropna(subset=[&#39;Speed_km_per_min&#39;, &#39;Delivery_person_Age_Group&#39;])<br><br># Average speed per age group<br>avg_speed_by_age = (<br>    df_speed.groupby(&#39;Delivery_person_Age_Group&#39;)[&#39;Speed_km_per_min&#39;]<br>    .mean()<br>    .reset_index()<br>    .rename(columns={&#39;Speed_km_per_min&#39;: &#39;Average_Speed_km_per_min&#39;})<br>)<br><br># Converting to km/h<br>avg_speed_by_age[&#39;Average_Speed_km_per_hr&#39;] = avg_speed_by_age[&#39;Average_Speed_km_per_min&#39;] * 60<br>avg_speed_by_age.drop(&#39;Average_Speed_km_per_min&#39;, axis=1, inplace=True)<br><br>print(&quot;Average Delivery Speed by Age Group:&quot;)<br>print(avg_speed_by_age)</pre><pre>Average Delivery Speed by Age Group:<br>  Delivery_person_Age_Group  Average_Speed_km_per_hr<br>0                     18-25                27.213999<br>1                     26-35                23.341065<br>2                     36-45                20.236109</pre><p>The average speed of the 18–25 age group is the highest (i.e., 27.2 km/hr), and for the 36–45 age group is the lowest, which aligns with the general observation that younger individuals tend to ride fast As we mentioned earlier, a higher speed may increase the rential accidents. For future enhancements of this analysis, we can find a correlation between speed and the probability of accidents.</p><h4>Fastest Combination:</h4><p>After all these bivariate analysis, we will do some multivariate analysis to find the fastest combination among all age groups and vehicle types having 4+ ratings for food delivery, which will be most optimal for a person who has ordered the food and is chtheirhis/her screen to see how much time the delivery will take:</p><pre># Droping rows that have NA in vehicle, age group or rating bin<br>cols_needed = [&#39;Type_of_vehicle&#39;, &#39;Delivery_person_Age_Group&#39;, &#39;Ratings_bin&#39;,<br>               &#39;Time_taken(min)&#39;]<br>df_triplet = df_clean[cols_needed].dropna(subset=[&#39;Type_of_vehicle&#39;,<br>                                                  &#39;Delivery_person_Age_Group&#39;,<br>                                                  &#39;Ratings_bin&#39;])<br><br># Grouping them<br>summary_triplet = (<br>    df_triplet<br>        .groupby([&#39;Type_of_vehicle&#39;,<br>                  &#39;Delivery_person_Age_Group&#39;,<br>                  &#39;Ratings_bin&#39;])[&#39;Time_taken(min)&#39;]<br>        .mean()<br>        .reset_index()<br>        .rename(columns={&#39;Time_taken(min)&#39;: &#39;Mean_Time&#39;})<br>)<br><br># fastest combination<br>fastest_row = summary_triplet.loc[summary_triplet[&#39;Mean_Time&#39;].idxmin()]<br><br># Sort the summary by Mean_Time ascending<br>sorted_summary = summary_triplet.sort_values(by=&#39;Mean_Time&#39;)<br><br># Find the second fastest combination<br>second_fastest_row = sorted_summary.iloc[1]<br><br>print(&quot;Fastest combination:&quot;)<br>print(fastest_row)<br><br>print(&quot;\nSecond fastest combination:&quot;)<br>print(second_fastest_row)</pre><pre>Fastest combination:                  Second fastest combination:<br>Type_of_vehicle            scooter    Type_of_vehicle            electric_scooter<br>Delivery_person_Age_Group  18-25      Delivery_person_Age_Group  18-25<br>Ratings_bin                4-5        Ratings_bin                4-5<br>Mean_Time                  20.925236  Mean_Time                 21.13273</pre><p>As we can see, the fastest and second fastest combination involves the optimal age group(18–25) for a food delivery person, and for vehicle types, only manual and electric scooters are the fastest in all age groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FZxxnuC1CAoy4dGjEq9nDg.jpeg" /><figcaption>Fastest Combination bar graph</figcaption></figure><h3><strong>Conclusion:</strong></h3><p>In this blog, we used a real-life dataset of food delivery times to analyze the factors affecting delivery time. After preprocessing and careful analysis, we were able to extract meaningful insights. From all the analyses, we can say that the fastest combination is with manual and electric scooters with persons aged 18–25, having ratings more than 4 among all the possible combinations with ratings more than 4. I hope you enjoyed the blog and learned some data analysis skills. Enjoy learning!</p><h4><strong>Additional Insights:</strong></h4><ol><li>IQR for time vs order type analysis shows the same results as shown without IQR, as mentioned, time shouldn’t vary with order type.</li><li><strong>Experience vs Efficiency</strong>: There was no correlation between a person with a larger number of orders delivered and ratings or time given by customers. Showing people prioritize time over the experience of the delivery person.</li></ol><pre>Average Rating by Experience Level:<br>  Experience_Level  Avg_Rating<br>0              Low    4.642693<br>1           Medium    4.637613<br>2             High    4.628297</pre><h4><strong>Future Enhancements:</strong></h4><p>There are several areas where this analysis can be enhanced:</p><ol><li><strong>Optimal route and path analysis</strong>: We can identify popular restaurants by finding the maximum number of orders to some particular coordinate and then finding the most optimal one.</li><li><strong>Accidents due to delivering food fast, </strong>lacking incidents reported in this dataset; if somehow a dataset provided incidents reported, too. We can find the probability of accidents caused by some specific paths or riding severely to deliver food fast.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c9700316b08" width="1" height="1" alt=""><hr><p><a href="https://medium.com/enjoy-algorithm/food-delivery-time-analysis-4c9700316b08">Food Delivery Time Analysis</a> was originally published in <a href="https://medium.com/enjoy-algorithm">EnjoyAlgorithms</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>