This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mlb = MultiLabelBinarizer() | |
# one-hot encoding + prefix | |
df = df.join(pd.DataFrame(mlb.fit_transform(df.pop('variants')), | |
columns=[x for x in mlb.classes_], | |
index=df.index)) | |
df = df.join(pd.DataFrame(mlb.fit_transform(df.pop('subsets')), | |
columns=['subsets_' + x for x in mlb.classes_], | |
index=df.index)) | |
df = df.join(pd.get_dummies(df['category'], prefix="category")).drop(['category'], axis=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# select only the columns we need | |
cols = ['family', 'variants', 'subsets', 'category'] | |
df = df[cols] | |
# df.head(5) | |
# Remove any space from family string so that it matchs with file name convention. | |
df.family = [name.replace(' ', '') for name in df.family] | |
df.head(5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# option 1. dynamically download JSON | |
# url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=' | |
# key = 'YOUR-API-KEY' | |
# data = pd.read_json(url+key, orient='') | |
# option 2. use JSON already downloaded (replace with your own file path) | |
df = pd.read_json('../../input/fonts-master.json') | |
# df.head() | |
# flatten the JSON hierarchy (easier to handle this way) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from sklearn.preprocessing import MultiLabelBinarizer | |
import pandas as pd | |
import numpy as np |
NewerOlder