-
Notifications
You must be signed in to change notification settings - Fork 0
/
love.py
33 lines (21 loc) · 792 Bytes
/
love.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
import re
import billboard
import pandas as pd
chart = billboard.ChartData('hot-100')
lovedic = {}
while chart.previousDate:
for s in chart:
if re.search("(?i)lov", s.title) or re.search("(?i)luv", s.title):
if (s.title, s.artist) not in lovedic:
lovedic[(s.title, s.artist)] = {}
if int(chart.date[:4]) not in lovedic[(s.title, s.artist)]:
lovedic[(s.title, s.artist)][int(chart.date[:4])] = 0
lovedic[(s.title, s.artist)][int(chart.date[:4])] += 1
chart = billboard.ChartData('hot-100', chart.previousDate)
lovelist = []
for k, v in lovedic.items():
title, artist = k
for year, count in v.items():
lovelist.append([title, artist, year, count])
lovedf = pd.DataFrame(lovelist, columns = ["Title", "Artist", "Year", "Count"])
lovedf.to_csv("lovedf.csv")