Music Comment Analysis and Visualization with Django

Data Collection Process

Music streaming platforms contain valuable user feedback. We colleect this data using Python web scraping techniques. The following example demonstrtaes fetching comments from a music platform:

import requests
from bs4 import BeautifulSoup

def get_song_comments(track_id):
    api_endpoint = f"https://api.music-service.com/tracks/{track_id}/comments"
    response = requests.get(api_endpoint)
    comment_data = response.json()
    return [item['text'] for item in comment_data['items']]

song_comments = get_song_comments('TRACK123')  # Example track ID

Data Processing

After collection, we clean and structure the data using Pandas:

import pandas as pd

comments_df = pd.DataFrame({'content': song_comments})
comments_df = comments_df.drop_duplicates().dropna()
comments_df['length'] = comments_df['content'].str.len()

Visualization Techniques

We generate insights through text analysis and visualization:

from wordcloud import WordCloud
import matplotlib.pyplot as plt

combined_text = ' '.join(comments_df['content'])
word_cloud = WordCloud(width=1200, height=600).generate(combined_text)

plt.figure(figsize=(12, 6))
plt.imshow(word_cloud)
plt.axis('off')
plt.show()

Django Integration

The analysis results are presented through a Django web application:

# views.py
from django.shortcuts import render
from analysis.models import SongAnalysis

def show_analysis(request, track_id):
    analysis = SongAnalysis.objects.get(track_id=track_id)
    return render(request, 'results.html', {'analysis': analysis})
<!-- results.html -->
<div class="analysis-container">
    <h2>Analysis for Track {{ analysis.track_id }}</h2>
    <div class="visualization">
        <img src="{{ analysis.cloud_image.url }}" alt="Comment Word Cloud">
    </div>
</div>

Tags: Django python Data Analysis web scraping Data Visualization

Posted on Sun, 07 Jun 2026 16:55:13 +0000 by Restless