Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 211 additions & 13 deletions 01_Billboard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "promotional-algorithm",
"metadata": {},
"outputs": [],
Expand All @@ -59,12 +59,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "civic-broad",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"200"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 200 status code means OK!"
"response = requests.get(url)\n",
"response.status_code"
]
},
{
Expand All @@ -77,11 +89,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "revised-digest",
"metadata": {},
"outputs": [],
"source": []
"source": [
"soup = BeautifulSoup(response.content, \"html.parser\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -93,20 +107,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "falling-chambers",
"metadata": {},
"outputs": [],
"source": [
"# song titles\n",
"songs = soup.find_all(\"span\", class_=\"chart-element__information__song text--truncate color--primary\")\n",
"\n",
"# artists\n",
"artists = soup.find_all(\"span\", class_=\"chart-element__information__artist text--truncate color--secondary\")\n",
"\n",
"# last week\n",
"last_week_ranks = soup.find_all(\"span\", class_= \"chart-element__meta text--center color--secondary text--last\")\n",
"\n",
"# peak rank\n",
"peak_ranks = soup.find_all(\"span\", class_= \"chart-element__meta text--center color--secondary text--peak\")\n",
"\n",
"# weeks on chart\n"
"# weeks on chart\n",
"weeks_on_chart = soup.find_all(\"span\", class_= \"chart-element__meta text--center color--secondary text--week\")"
]
},
{
Expand All @@ -119,11 +138,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "amateur-protocol",
"metadata": {},
"outputs": [],
"source": []
"source": [
"for i in [songs, artists, last_week_ranks, peak_ranks, weeks_on_chart]:\n",
" for j in range(len(i)):\n",
" i[j] = i[j].getText()"
]
},
{
"cell_type": "markdown",
Expand All @@ -135,11 +158,186 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "external-instrumentation",
"metadata": {},
"outputs": [],
"source": []
"source": [
"billboard = pd.DataFrame(\n",
" {\"song\": songs,\n",
" \"artist\": artists,\n",
" \"last_week_rank\": last_week_ranks,\n",
" \"peak_rank\": peak_ranks,\n",
" \"weeks_on_chart\": weeks_on_chart}\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "05549a2f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>song</th>\n",
" <th>artist</th>\n",
" <th>last_week_rank</th>\n",
" <th>peak_rank</th>\n",
" <th>weeks_on_chart</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Stay</td>\n",
" <td>The Kid LAROI &amp; Justin Bieber</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Industry Baby</td>\n",
" <td>Lil Nas X &amp; Jack Harlow</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Fancy Like</td>\n",
" <td>Walker Hayes</td>\n",
" <td>5</td>\n",
" <td>3</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Way 2 Sexy</td>\n",
" <td>Drake Featuring Future &amp; Young Thug</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bad Habits</td>\n",
" <td>Ed Sheeran</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
" <td>Esta Danada</td>\n",
" <td>Ivan Cornejo</td>\n",
" <td>-</td>\n",
" <td>96</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>96</th>\n",
" <td>Whiskey And Rain</td>\n",
" <td>Michael Ray</td>\n",
" <td>-</td>\n",
" <td>97</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>97</th>\n",
" <td>TSU</td>\n",
" <td>Drake</td>\n",
" <td>84</td>\n",
" <td>9</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>98</th>\n",
" <td>Love All</td>\n",
" <td>Drake Featuring JAY-Z</td>\n",
" <td>87</td>\n",
" <td>10</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99</th>\n",
" <td>No Where</td>\n",
" <td>YoungBoy Never Broke Again</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" song artist last_week_rank \\\n",
"0 Stay The Kid LAROI & Justin Bieber 2 \n",
"1 Industry Baby Lil Nas X & Jack Harlow 3 \n",
"2 Fancy Like Walker Hayes 5 \n",
"3 Way 2 Sexy Drake Featuring Future & Young Thug 4 \n",
"4 Bad Habits Ed Sheeran 6 \n",
".. ... ... ... \n",
"95 Esta Danada Ivan Cornejo - \n",
"96 Whiskey And Rain Michael Ray - \n",
"97 TSU Drake 84 \n",
"98 Love All Drake Featuring JAY-Z 87 \n",
"99 No Where YoungBoy Never Broke Again 40 \n",
"\n",
" peak_rank weeks_on_chart \n",
"0 1 13 \n",
"1 2 11 \n",
"2 3 16 \n",
"3 1 5 \n",
"4 2 15 \n",
".. ... ... \n",
"95 96 1 \n",
"96 97 1 \n",
"97 9 5 \n",
"98 10 5 \n",
"99 40 2 \n",
"\n",
"[100 rows x 5 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"billboard"
]
}
],
"metadata": {
Expand All @@ -158,7 +356,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.8.8"
},
"toc": {
"base_numbering": 1,
Expand Down