Page 263 - Robotics and AI class 10
P. 263

'Year': [2019, 2020, 2021, 2022, 2023],

                     'Selling Price': [500, 550, 600, 650, 700],

                     'Original Price': [400, 450, 600, 700, 650]
                 }

                 df = pd.DataFrame(data)

                 # Plotting the line plot for selling price and original price
                 plt.figure(figsize=(8, 5))

                 plt.plot(df['Year'], df['Selling Price'], marker='o', label='Selling Price')
                 plt.plot(df['Year'], df['Original Price'], marker='s', label='Original Price')

                 plt.xlabel('Year')
                 plt.ylabel('Price')

                 plt.title('Selling Price and Original Price Over Years')

                 plt.legend()
                 plt.grid(True)

                 plt.tight_layout()
                 plt.show()
                 Output:
























              12.  Plotting bar graphs - Use the bestselling book dataset to plot year wise data and find out what genre was
                 bestselling across years.

              Ans.  import pandas as pd

                 import matplotlib.pyplot as plt
                 # Create a small dataset with bestselling book data

                 data = {
                     'Year': [ 2019, 2019, 2020, 2021, 2021, 2022, 2023,2023],

                     'Genre': ['Fiction', 'Non-Fiction', 'Fiction', 'Non-Fiction', 'Mystery',


                                                                                            Assignment     261
   258   259   260   261   262   263   264   265   266   267   268