0

我有一个dataframe通过 txt 文件读入的熊猫:

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 (last last call last) in () 1 ----> 2 plot = ggplot(training, aes(x='num_visits')) + geom_density() +xlim(0,20) +facet_wrap( ~ 'segment ') 3 打印情节

TypeError:一元操作数类型错误〜:'str'

4

1 回答 1

2

在 yhat ggplot 中,facet 选项不带“~”。您可以在文档中找到它(为方便起见,在此处复制):

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")
于 2016-03-22T22:26:29.567 回答