Page 320 - Ai_V3.0_c11_flipbook
P. 320

3.   The following data is stored in a csv file named ‘data.csv’. Prepare a histogram of the following
                         distribution using Python:
                        Class
                       interval   10-15    15-20    20-25    25-30    30-35    35-40    40-45    45-50   50-55
                      Frequency     3        5        6        9        5        4        3       2        1
                    Ans.

                         import matplotlib.pyplot as plt
                         import pandas as pd
                         # Load data from CSV file
                         data = pd.read_csv('data.csv')
                         # Extract class intervals and frequency from the loaded data
                         class_intervals = data['Class interval']
                         frequency = data['Frequency']
                         # Create histogram
                         plt.bar(class_intervals, frequency, color='skyblue')
                         # Add title and labels
                         plt.title('Frequency Distribution')
                         plt.xlabel('Class Interval')
                         plt.ylabel('Frequency')
                         # Rotate x-axis labels for better readability
                          plt.xticks(rotation=45) #The x-axis labels are rotated by 45 degrees for
                         better readability.
                         # Show plot
                         plt.show()






















                    4.   My Netflix viewing capacity is given in a table as follows:

                              Day      Monday    Tuesday   Wednesday Thursday     Friday   Saturday   Sunday

                          No. of hours 5         4         7           3         8         9         10
                         Prepare a bar chart using Python.
                    Ans.

                         import matplotlib.pyplot as plt

                         # Data


                    318     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   315   316   317   318   319   320   321   322   323   324   325