Reputation: 9
I have a data set with a few columns and rows
I have to create a bar graph of the mean revenues from the year 2006-2011 and 2012-2016
I've already tried using if
statements to separate the revenues from 2006-11 and 2012-16 but getting errors.
if movie_data['Year']<=2011:
movie_data['rev_new']=movie_data['Revenue (Millions)']
print(movie_data)
Upvotes: 0
Views: 31
Reputation: 586
I would create two bins for the two time windows by manually specifying your desired time frames
bins = pd.cut(pd.to_datetime(df['year']), bins=[pd.to_datetime('2006'), pd.to_datetime('2011'), pd.to_datetime('2016')])
Then group your dataframe by these bins and create your bar chart
df = df.groupby(bins).mean()
df['Revenue (Millions)'].plot(kind='bar')
Upvotes: 1
Reputation: 42352
You can separate the dataframe in this way:
before_2011 = movie_data[movie_data['Year'] <= 2011]
after_2012 = movie_data[movie_data['Year'] >= 2012]
and access the revenues as:
before_2011['Revenue (Millions)']
Upvotes: 0