【发布时间】:2016-05-25 05:08:08
【问题描述】:
我想绘制从 couchdb 形成的 pandas 数据框列中的数据。这是数据的代码和输出:
print df4.Patient_Age
Doc_ID
000103f8-7f48-4afd-b532-8e6c1028d965 99
00021ec5-9945-47f7-bfda-59cf8918f10b 92
0002510f-fb89-11e3-a6eb-742f68319ca7 32
00025550-9a97-44a4-84d9-1f6f7741f973 73
0002d1b8-b576-4db7-af55-b3f26f7ca63d 49
0002d40f-2b45-11e3-8f66-742f68319ca7 42
000307eb-18a6-47cd-bb03-33e484fad029 18
00033d3d-1345-4739-9522-b41b8db3ee23 42
00036d2e-0a51-4cfb-93d1-3e137a026f19 42
0003b054-5f3b-4553-8104-f71d7a940d84 10
Name: Patient_Age, dtype: object
如果我执行这段代码:
sns.kdeplot(df4.Patient_Age)
情节按预期生成。但是,当我运行它时:
sns.distplot(df4.Patient_Age)
distplot 出现以下错误:
TypeError: unsupported operand type(s) for /: 'unicode' and 'long'
为了纠正错误,我使用:
df4.Patient_Age = [int(i) for i in df4.Patient_Age]
all(isinstance(item,int) for item in df4.Patient_Age)
输出是:
False
我想了解的是:
- 为什么更早生成了 kdeplot 而不是 histplot?
- 当我将数据类型更改为
int时,为什么我仍然得到False?而如果数据不是int(如False所示),为什么转换后histplot会起作用?
【问题讨论】:
标签: python pandas matplotlib analytics seaborn