BillboardDataFormation



In [ ]:
import billboard
import pandas as pd
import datetime

threshold_date = datetime.datetime.strptime("12/31/2016", "%m/%d/%Y")
chartData = pd.DataFrame(columns = ['Name','Artists'])
index = 0
 
chart = billboard.ChartData('hot-100')
chartDataList = []
for i in range(100):
    chartDataList.append(str(chart[i]))
    chartData.loc[index]= [str(chart[i].title),",".join(map(str.strip,((chart[i].artist).replace('Featuring','&').split('&'))))]
    index += 1

chart = billboard.ChartData('hot-100', chart.previousDate)
chart_previous_date = datetime.datetime.strptime(chart.previousDate, '%Y-%m-%d')

print(chart_previous_date)
while chart.previousDate and (chart_previous_date > threshold_date):
    chartDataList = []
    for i in range(100):
        chartDataList.append(str(chart[i].title))
        chartData.loc[index]= [str(chart[i].title),",".join(map(str.strip,((chart[i].artist).replace('Featuring','&').split('&'))))]
        index += 1

    temp = pd.DataFrame(chartDataList)
    
    chart = billboard.ChartData('hot-100', chart.previousDate)
    chart_previous_date = datetime.datetime.strptime(chart.previousDate, '%Y-%m-%d')
    print(chart_previous_date)

In [ ]:
chartData.drop_duplicates().reset_index(drop=True).to_csv('Billboard2017Songs.csv')