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

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
  • 写回答

2条回答 默认 最新

  • 爱晚乏客游 2022-02-10 12:38
    关注

    pd.CategoricalDtype()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月18日
  • 已采纳回答 2月10日
  • 创建了问题 2月10日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器