我有一個pandas
dataframe
有列:問題與熊貓和半對數爲箱線圖
「視頻」,並點擊「鏈接」以日期時間的索引值
。出於某種原因,當我使用semilogy和箱線與視頻系列中,我得到的錯誤
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)
這裏是
type link video created_time我運行視頻序列中的碼相關的輸出完全相同的代碼,除了我做
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 5there is 5463 nan values in video
a.types_pivot['link']
,我能夠繪製箱線圖。
下面是從環系列
Index: 5269 entries, 2011-01-24 20:03:58+00:00 to 2012-06-22 16:56:30+00:00 Data columns: link 5269 non-null values photo 0 non-null values question 0 non-null values status 0 non-null values swf 0 non-null values video 0 non-null values dtypes: float64(6)there is 216 nan values in link
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'中移除NaNs? –
大點振亞!是的,我確實嘗試過。 'PLT。boxplot(temp ['video'])'通過使用我的臨時變量,我有非空值,它確實工作。我不明白爲什麼直接調用它時不起作用,因爲它適用於「鏈接」系列。如果它有效,那麼我可以輕鬆地使用熊貓.boxplot和.hist函數與semilog來比較數據 –