Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
79 views
in Technique[技术] by (71.8m points)

How to create a class from this code at python

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...