【问题标题】:yhat ggplot facet_wrap type erroryhat ggplot facet_wrap 类型错误
【发布时间】:2016-07-09 22:56:15
【问题描述】:

我有一个熊猫 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(最近调用 最后)在() 1 ----> 2 plot = ggplot(training, aes(x='num_visits')) + geom_density() +xlim(0,20) +facet_wrap(~'segment') 3 打印情节

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

【问题讨论】:

    标签: python ggplot2 facet-wrap python-ggplot


    【解决方案1】:

    在 yhat ggplot 中,facet 选项不带“~”。您可以在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")
    

    【讨论】:

    • 我看到了一个例子,但没有文档。你回答说,“你可以在文档中找到这个(为方便起见,复制到这里):”
    猜你喜欢
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 2017-01-17
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多