is there an elegant way to create a class from the attached code:
ratings_data = { 'TV-PG': 7,'TV-MA': 18,'TV-Y7-FV': 7,'TV-Y7': 7,
'TV-14': 16,'R': 18,'TV-Y': 0,'NR': 18,'PG-13': 13,
'TV-G': 0,'PG': 7,'G': 0,'UR': 18,'NC-17': 18}
ratings = pd.Series(ratings_data, name='age')
ages_data = {0: 'Kids', 7: 'Older Kids', 13: 'Teens', 16: 'Young Adults', 18: 'Adults'}
ages = pd.Series(ages_data, name='description')
ratings_netflix = pd.merge(ratings, ages, left_on='age', right_index=True)
age_bins = [-1, 17, 19]
ratings_netflix['18+'] = pd.cut(ratings_netflix['age'], age_bins, labels=['No', 'Yes'])
ratings_netflix['description'] = pd.Categorical(ratings_netflix['description'],
categories=['Kids', 'Older Kids', 'Teens', 'Young Adults', 'Adults'],
ordered=True)
ratings_netflix['age'] = pd.Categorical(ratings_netflix['age'], ordered=True)
ratings_netflix
question from:
https://stackoverflow.com/questions/65861419/how-to-create-a-class-from-this-code-at-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…