如何在熊猫中转换类别名称

时间:2019-12-21 11:52:29

标签: python pandas

我想更改类别名称,所以我尝试使用此代码,但是在将名称形式的数字转换为level_names中的名称之后,我得到了一个空图

Level_names = [ 'Not Available', 'Debt Consolidation', 'Home Improvement', 'Business', 'Personal Loan','Student Use', 'Auto', 'Other', 'Baby&Adoption', 'Boat', 'Cosmetic Procedure', 'Engagement Ring',Green Loans', 'Household Expenses', 'Large Purchases', 'Medical/Dental', 'Motorcycle', 'RV', 'Taxes', 'Vacation', 'Wedding Loans']

levels_order = pd.api.types.CategoricalDtype(ordered = True, categories = Level_names)

df['ListingCategory (numeric)'] = df['ListingCategory (numeric)'].astype(levels_order)

order_LC = df['ListingCategory (numeric)'].value_counts().index
sb.countplot(data=df, y='ListingCategory (numeric)', color = colors, order = order_LC );

我的错误是什么?

0 个答案:

没有答案