Autism_mauve_ 2022-02-10 12:35 采纳率: 71.4%
浏览 401
已结题

jupyter报错:NameError: name 'CategoricalDtype' is not defined

jupyter报错一直报错,显示 NameError: name 'CategoricalDtype' is not defined ,应该咋样改呀


#核密度估计峰峦图
import pandas as pd
import numpy as np
import joypy
import matplotlib.pyplot as plt
from matplotlib import cm
import seaborn as sns
plt.rc('font',family='Times New Roman')
sns.set_context("notebook", font_scale=1.5,
                rc={'font.size': 12, 
                    'axes.labelsize': 20, 'legend.fontsize':15, 
                    'xtick.labelsize': 15,'ytick.labelsize': 15})

df = pd.read_csv("lincoln_weather.csv")
Categories=['January', 'February', 'March', 'April', 'May', 'June','July',
            'August','September', 'October', 'November','December']
df['Month']=df['Month'].astype(CategoricalDtype(categories=Categories,ordered=True))  #-------报错行--------

fig, axes = joypy.joyplot(df, column=["Mean.Temperature..F."], 
                          by="Month", ylim='own',colormap=cm.Spectral_r,#color='#FF8B19',
                          #hist=True,bins=30,
                          alpha= 0.9,figsize=(6,5))
plt.xlabel("Mean Temperature",{'size': 15 })
plt.ylabel("Month",{'size': 15 })
axes.set_axis_labels("Mean Temperature", "Month")   
plt.show()
#fig.savefig('joyplot.pdf')

报错:
NameError                                 Traceback (most recent call last)
d:\temp/ipykernel_45616/100926297.py in <module>
      7 Categories=['January', 'February', 'March', 'April', 'May', 'June','July',
      8             'August','September', 'October', 'November','December']
----> 9 df['Month']=df['Month'].astype(CategoricalDtype(categories=Categories,ordered=True))
     10 
     11 fig, axes = joypy.joyplot(df, column=["Mean.Temperature..F."], 

NameError: name 'CategoricalDtype' is not defined
  • 写回答

1条回答 默认 最新

  • Lin9977 2022-02-11 15:22
    关注

    CategoricalDtype 这个函数(?)没有声明或者引用,不能直接用。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月10日
  • 已采纳回答 5月10日
  • 创建了问题 2月10日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度