This content originally appeared on DEV Community and was authored by ANNA LAPUSHNER
100% awesome. The interactive 3D scatterplot is so killer. The key to making a great scatter plot is picking 3 axis points that can be correlated AND choosing a mean/average of a manageable number of features.
I love it! Hope you do too!
# Create a killer 3d scatter plot of company revenue. The axis points are the top 10 restaurants, average order and rating
# Calculate average order value for each restaurant
avg_order_value = df.groupby('restaurant_name')['cost_of_the_order'].mean()
# Calculate average rating for each restaurant
avg_rating = df_rated.groupby('restaurant_name')['rating'].mean()
# Get top 10 restaurants by revenue
top_10_restaurants = revenue_by_restaurant.head(10).index
# Filter data for top 10 restaurants
df_top10 = df[df['restaurant_name'].isin(top_10_restaurants)]
# Create a new DataFrame for plotting
plot_df = pd.DataFrame({
'Restaurant': top_10_restaurants,
'Revenue': revenue_by_restaurant.loc[top_10_restaurants],
'Average Order Value': avg_order_value.loc[top_10_restaurants],
'Average Rating': avg_rating.loc[top_10_restaurants]
})
# Create 3D scatter plot
fig = px.scatter_3d(plot_df, x='Average Order Value', y='Average Rating', z='Revenue',
color='Restaurant', size_max=10, opacity=0.7)
fig.update_layout(title='Company Revenue vs. Average Order Value and Rating (Top 10 Restaurants)',
scene=dict(xaxis_title='Average Order Value',
yaxis_title='Average Rating',
zaxis_title='Revenue'))
This content originally appeared on DEV Community and was authored by ANNA LAPUSHNER
ANNA LAPUSHNER | Sciencx (2024-08-13T19:50:02+00:00) kill it with the 3D scatter plot. Retrieved from https://www.scien.cx/2024/08/13/kill-it-with-the-3d-scatter-plot/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.