简体   繁体   English

yhat ggplot facet_wrap类型错误

[英]yhat ggplot facet_wrap type error

I have a pandas dataframe that I read in via txt file: 我有一个通过txt文件读取的熊猫dataframe

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

These are the columns: 这些是列:

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

I'm interested in a graph that shows the density of num_page_views by segment, like so: 我对按段显示num_page_views密度的图形感兴趣,如下所示:

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

And it gives the following error : 它给出了以下错误

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误差追踪(最近一次通话是最近的)(1)-> 2图= ggplot(training,aes(x ='num_visits'))+ geom_density()+ xlim(0,20)+ facet_wrap(〜'segment ')3个打印图

TypeError: bad operand type for unary ~: 'str' TypeError:一元运算符的错误操作数类型〜:“ str”

In yhat ggplot, the facet option does not take a "~". 在ygg ggplot中,facet选项不带“〜”。 You can find this is in the documentation (copied here for convenience): 您可以在文档中找到(为方便起见,请在此处复制):

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM