【发布时间】:2012-06-27 07:18:57
【问题描述】:
我有一个 pandas dataframe 有列:
点击值的“视频”和“链接”
带有日期时间索引。出于某种原因,当我在视频系列中使用符号学和箱线图时,我得到了错误
ValueError: Data has no positive values, and therefore can not be log-scaled.
但是当我在“链接”系列上这样做时,我可以正确绘制箱线图。
我已验证 “视频”和“链接”系列具有 NaN 值和正值。
对为什么会发生这种情况有任何想法吗?以下是我为验证情况所做的工作
以下是示例代码:
#get all the not null values of video to show that there are positive
temp=a.types_pivot[a.types_pivot['video'].notnull()]
print temp
#get a count of all the NaN values to show both 'video' and 'link' has NaN
count = 0
for item in a.types_pivot['video']:
if(item.is_integer() == False):
count += 1
#try to draw the plots
print "there is %s nan values in video" % (count)
fig=plt.figure(figsize=(6,6),dpi=50)
ax=fig.add_subplot(111)
ax.semilogy()
plt.boxplot(a.types_pivot['video'].values)
这是视频系列代码的相关输出
输入链接视频 创建时间2011-02-10 15:00:51+00:00 NaN 5 2011-02-17 17:50:38+00:00 NaN 5 2011-03-22 14:04:56+00:00 NaN 5
视频中有 5463 个 nan 值
我运行相同的确切代码,除了我这样做a.types_pivot['link']
我可以画出箱线图。
以下是链接系列的相关输出
索引:5269 个条目,2011-01-24 20:03:58+00:00 到 2012-06-22 16:56:30+00:00 数据列: 链接 5269 个非空值 照片 0 非空值 问题 0 非空值 状态 0 非空值 swf 0 非空值 视频 0 非空值 数据类型:float64(6)链接中有 216 个 nan 值
Using the describe function
a.types_pivot['video'].describe()
<pre>
count 22.000000
mean 16.227273
std 15.275040
min 1.000000
25% 5.250000
50% 9.500000
75% 23.000000
max 58.000000
</pre>
【问题讨论】:
-
您是否尝试从
a.types_pivot['video'].values中删除 NaN? -
好点真雅!是的,我确实尝试过。
plt.boxplot(temp['video'])通过使用我的临时变量,我有非空值并且它确实有效。我不明白为什么当我直接调用它时它不起作用,因为它适用于“链接”系列。如果可行,那么我可以轻松地使用 pandas 的 .boxplot 和 .hist 函数与 semilog 来比较数据
标签: matplotlib pandas