[英]yhat ggplot facet_wrap type error
我有一個通過txt文件讀取的熊貓dataframe
:
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誤差追蹤(最近一次通話是最近的)(1)-> 2圖= ggplot(training,aes(x ='num_visits'))+ geom_density()+ xlim(0,20)+ facet_wrap(〜'segment ')3個打印圖
TypeError:一元運算符的錯誤操作數類型〜:“ str”
在ygg 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")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.