How to create a simple Dashboard
by CubodeDevelopment
Cubode
Use this Template
Cubode
Template Schema

Template graphical representation

Generated Code

Code generated from template representation, generate code of any template in cubode.com


Analyzing Startup Valuations with Python: Bar Plot and Pie Chart

In this blog post, we will use Python to analyze and visualize startup valuations using both bar plots and pie charts. We will fetch the data of startups with billion-dollar valuations from a remote URL and plot the average valuation by industry using a bar plot and the count of startups by country using a pie chart. This tutorial is designed for data analysts who are code enthusiasts and want to learn how to create insightful visualizations for startup valuation data.

1. Introduction to the Code


The provided Python code allows us to create both bar plots and pie charts to analyze startup valuations. We will fetch the startup valuation data from a remote URL and then use Plotly Express to create a bar plot to visualize the average valuation by industry and a pie chart to show the count of startups by country.


%pip install plotly
%pip install pandas

import plotly.express as px
import plotly.io
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import pandas as pd

def MainCanvas():
    def PieChartPlot(dataframe, values, names, title):
        # Code to create a pie chart using Plotly Express
        ...

    def BarPlot(dataframe, values, labels, title):
        # Code to create a bar plot using Plotly Express
        ...

    def StartupsBillionValuation2021_fun():
        # Code to fetch startup valuation data from URL
        ...

    StartupsBillionValuation2021 = StartupsBillionValuation2021_fun()
    Select_Out = StartupsBillionValuation2021[['Company', 'Valuation ($B)', 'Industry', 'Country']]
    Group_Out = Select_Out.groupby(by='Industry', as_index=False).agg('mean')
    Group1_Out = Select_Out.groupby(by='Country', as_index=False).agg('count')
    BarPlot(Group_Out, values='Valuation ($B)', labels='Industry', title='Average Valuation of Startup By Industry')
    PieChartPlot(Group1_Out, values='Valuation ($B)', names='Country', title='Count of Startups by Country')
    return

MainCanvas()
        

The code uses Plotly Express to create both bar plots and pie charts, Pandas to fetch the startup valuation data from the remote URL, and then visualizes the average valuation by industry and the count of startups by country.



2. Explaining the Functions


Let's briefly explain the functions used in the code:

1. BarPlot()


This function is responsible for creating the bar plot to visualize the average valuation by industry. It takes four parameters: dataframe (the Pandas DataFrame containing the data), values (the name of the column containing the values for the bars), labels (the name of the column containing the labels for the x-axis), and title (the title of the plot).

2. PieChartPlot()


This function is responsible for creating the pie chart to visualize the count of startups by country. It takes four parameters: dataframe (the Pandas DataFrame containing the data), values (the name of the column containing the values for the pie slices), names (the name of the column containing the labels for the pie slices), and title (the title of the plot).

By utilizing these functions, we fetch and prepare the data for startup valuations and then create a bar plot to show the average valuation by industry and a pie chart to display the count of startups by country.



3. Conclusion


Congratulations! You've learned how to use Python to fetch, process, and visualize startup valuations using both bar plots and pie charts with Plotly and Pandas. Bar plots are ideal for showing the average valuation by industry, while pie charts are effective for illustrating the distribution of startups across different countries. Continue exploring other visualization types and datasets to further enhance your data analysis and coding skills!