Page 264 - Robotics and AI class 10
P. 264
'Non-Fiction', 'Mystery', 'Mystery'],
'Sales': [1200, 800, 1400, 1000, 1600, 1100, 1700, 1300]
}
df = pd.DataFrame(data)
# Calculate the total sales for each genre by year
sales_by_genre_year = df.groupby(['Year', 'Genre'])['Sales'].sum().unstack()
# Plotting the bar graph for sales by genre across years
plt.figure(figsize=(10, 4))
sales_by_genre_year.plot(kind='bar', stacked=True)
plt.xlabel('Year')
plt.ylabel('Total Sales')
plt.title('Sales by Genre Across Years')
plt.legend(title='Genre')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
# Find the bestselling genre across years
bestselling_genre_by_year = sales_by_genre_year.idxmax()
print("Bestselling Genre Across Years:")
print(bestselling_genre_by_year)
Output:
262 Touchpad Robotics & Artificial Intelligence-X

