我正在玩熊猫并拥有以下代码:
tips.hist(stacked = True,column =“total_bill”,by =“time”)
结果图看起来不错:
然而,它没有堆叠!我想把它们都放在一块地上,堆叠在一起。我希望它看起来像文档中的那个:http://pandas.pydata.org/pandas-docs/stable/visualization.html#histograms
非常感谢任何帮助。
答案 0 :(得分:0)
您需要单独列中的值。
case class Ids(Ids: Seq[String])
case class Id(Id: String)
case class Name(Name: String)
case class OnHand(OnHand: Int)
case class LoyaltyId(LoyaltyId: Int)
case class ProductPrice(RetailPrice: Double,
RetailPriceSymbol: String,
PromotionPrice: Double,
PromotionPriceSymbol: String)
case class Product(Name: String,
ProductCategory: String,
InventoryTrackingNumberType: String,
InventoryTrackingNumber: String,
ProductPrice: ProductPrice)
object MyJsonProtocol2 extends DefaultJsonProtocol {
implicit val nameFormat = jsonFormat1(Name)
implicit val productPriceFormat = jsonFormat4(ProductPrice)
implicit val productFormat = jsonFormat5(Product)
implicit val loyaltyIdFormat = jsonFormat1(LoyaltyId)
implicit val onHandFormat = jsonFormat1(OnHand)
implicit val idFormat = jsonFormat1(Id)
implicit val idsFormat = jsonFormat1(Ids)
implicit val dateFormat = jsonFormat20(Data)
implicit val claXFormat2 = jsonFormat8(claX2)
}
tips = pd.read_csv('https://raw.github.com/pydata/pandas/master/pandas/tests/data/tips.csv')
>>> tips[['time', 'tip']].pivot(columns='time').plot(kind='hist', stacked=True)