Py.Cafe

banana0000/

dash-popularity-programming-languages

Popularity of Programming Languages Over Time

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from dash import Dash, dcc, html
import plotly.express as px
import pandas as pd

# Load data
df = pd.read_csv("https://raw.githubusercontent.com/plotly/Figure-Friday/refs/heads/main/2025/week-10/Popularity%20of%20Programming%20Languages%20from%202004%20to%202024.csv")

# Convert 'Date' to year only and ensure it's in int type
df['Date'] = pd.to_datetime(df['Date']).dt.year
df['Date'] = df['Date'].astype(int)

# Get the last 5 years
last_5_years = sorted(df['Date'].unique(), reverse=True)[:5]

# Filter the data to only include the last 5 years
df_filtered = df[df['Date'].isin(last_5_years)]

# Reshape the data to have 'Programming Language' and 'Popularity'
df_melted = df_filtered.melt(id_vars=["Date"], var_name="Programming Language", value_name="Popularity")

# Sort the dataframe by 'Popularity' in descending order, and keep only the top 10 languages
top_10_languages = df_melted.groupby("Programming Language")["Popularity"].mean().sort_values(ascending=False).head(10).index
df_melted_top10 = df_melted[df_melted['Programming Language'].isin(top_10_languages)]

# Rank the languages based on their average popularity (1 = most popular, 5 = least popular)
df_melted_top10['Ranking'] = df_melted_top10.groupby('Date')['Popularity'].rank(ascending=False, method='min')

# Normalize the 'Popularity' column to make sure values stay between 0 and 100%
df_melted_top10['Popularity'] = df_melted_top10['Popularity'] / df_melted_top10['Popularity'].max() * 100

# Create a Sunburst chart for the last 5 years (with 'Date' as the root node) with the top 10 languages
sunburst_fig = px.sunburst(df_melted_top10, 
                           path=["Date", "Programming Language"], 
                           values="Popularity", 
                           title="Top 10 Programming Languages by Popularity (Last 5 Years)",
                           color="Popularity", 
                           color_continuous_scale="oranges")

# Customize the tooltip to show only 2 lines: Language and Ranking
sunburst_fig.update_traces(
    hovertemplate='<b>%{label}</b><br>Ranking: %{customdata[0]}</b>',
    customdata=df_melted_top10[['Ranking']].values  # Pass the ranking as custom data for the tooltip
)

# Dash app layout
app = Dash()
app.layout = [
    dcc.Graph(
        figure=sunburst_fig,  # Sunburst chart of top 10 programming languages popularity by year
        style={'height': '90vh', 'width': '100%'}  # Set size to be larger (90% of the viewport height)
    )
]

if __name__ == "__main__":
    app.run(debug=True)