【发布时间】:2019-02-07 12:45:44
【问题描述】:
这实际上是我上一个问题的后续问题。
pandas: How to plot the pie diagram for the movie counts versus genre of IMDB movies in pandas?
在那个问题中,我们绘制了电影的独特类型的数量。
我的问题是:如何在pandas 中获得'budget' 与'genres' 的图?
这里是示例代码:
import pandas as pd
import numpy as np
%matplotlib inline
df = pd.DataFrame({'movie' : ['A', 'B','C','D'],
'budget': [1000, 2000, 3000, 4000],
'genres': ['Science Fiction|Romance|Family', 'Action|Romance',
'Family|Drama','Mystery|Science Fiction|Drama']},
index=range(4))
df
这里的流派Science Fiction|Romance|Family实际上是三个独立的流派。
Science Fiction 出现在电影A 和B 中,所以Science Fiction 类型的预算应该是1000+4000=5000 等等。
【问题讨论】:
-
使用
df.plot(x='genres', y='budget')绘制简单的线图。请通过this 了解更多详情。 -
你应该试着在第一时间把你的问题和你想要的更清楚。这样可以节省每个人的编辑时间。