Exemplo n.º 1
0
    track_data = []
    popularity = track["track"]["popularity"]
    if popularity == 0:
        continue #skip any track with 0 popularity, because I'm unsure if this is a default value 
    else:
        #name = track["track"]["name"]
        #track_data.append(name) # will be ignored but could but each track_data_obj should be identifiable
        features_dict = sp.audio_features(track["track"]["id"]) #this  returns a features dictonary
        for key in features_dict[0]: #loop through and add only the attributes we want
            if key != "type" and key != "id" and key != "uri" and key != "track_href" and key != "analysis_url" and key != "time_signature" and key != "mode" and key != "key" and key != "loudness":
                val = features_dict[0][key]
                if key != "tempo" and key != "duration_ms":
                    val = myutils.percent_to_rating(val)
                track_data.append(val)
                # if first == True:
                #     header.append(key)
        # first = False
        pop_class = myutils.pop_rating(popularity)
        track_data.append(pop_class) # popularity will be the y_train
        track_data_objs.append(track_data)
# header.append("popularity")
# now we can turn this into an xtrain and ytrain or keep it stitched together 
# when dealing with the data we can delete the first col, which is the name identifier

print(len(track_data_objs))

header = ['danceability', 'energy', 'speechiness', 'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo', 'duration_ms', 'popularity']

tracks_mypy = MyPyTable(header, track_data_objs)
tracks_mypy.save_to_file("tracks_data.txt")
  
Exemplo n.º 2
0
from mysklearn.mypytable import MyPyTable

# Object Declaration
table = MyPyTable()

# Trims the Dataset (Gets Data Based on City)
city = "Sydney"
table.load_from_file("weatherAUS.csv")
table.column_names[0] = 'Location'
names, tables = table.group_by("Location")

city_index = names.index(city)

print("\n")
for i in range(10):
    print(tables[city_index][i])

table.data = tables[city_index]

table.save_to_file(city+"_weather.csv")