2016-03-22 51 views
0

我有我通過txt文件讀入數據幀大熊貓:yhat ggplot facet_wrap類型的錯誤

training = pd.read_csv('training_data.txt')

這些都是列:

>> print training.columns.values
['segment' 'cookie_id' 'num_visits' 'num_page_views']

我對分段顯示'num_page_views'的密度感興趣,如下所示:

plot = ggplot(training, aes(x='num_visits')) + geom_density() 
     + xlim(0,20) + facet_wrap(~ 'segment') 
print plot 

而且它提供了以下錯誤

TypeError Traceback (most recent call last) in() 1 ----> 2 plot = ggplot(training, aes(x='num_visits')) + geom_density() +xlim(0,20) +facet_wrap(~ 'segment') 3 print plot

TypeError: bad operand type for unary ~: 'str'

回答

2

在yhat ggplot,小面選項不採取 「〜」。你可以找到這是在documentation(複製在這裏爲了方便):

import pandas as pd 

meat_lng = pd.melt(meat, id_vars=['date']) 

p = ggplot(aes(x='date', y='value'), data=meat_lng) 
p + geom_point() + \ 
    stat_smooth(colour="red") + \ 
    facet_wrap("variable") 

p + geom_hist() + facet_wrap("color") 

p = ggplot(diamonds, aes(x='price')) 
p + geom_density() + \ 
    facet_grid("cut", "clarity") 

p = ggplot(diamonds, aes(x='carat', y='price')) 
p + geom_point(alpha=0.25) + \ 
    facet_grid("cut", "clarity") 
+1

我看到一個例子,但沒有文件。你回答說:「你可以在文檔中找到它(爲方便起見,在這裏複製):」 –