Page 30 - Informatics_Practices_Fliipbook_Class12
P. 30

C T  09     Write Python statements to determine whether any of the record of an employee is missing in
                      the series: empNames and empSalary.








               isnull(): For every element of the series, the method returns True if the value is missing from the series,
               and False otherwise.


        1.5.7 Mathematical Operations Involving More than One Series:

        Pandas provides various mathematical operations that can be performed on Series data, making it an ideal for analyzing
        data.
        Example 1: Profit over four quarters
        Suppose we have two Series that contain the sales and expenses data for a company over four quarters, respectively.
        We can subtract the expenses from the sales to obtain the profit for each quarter, as given below:

          01 import pandas as pd
          02 salesData = [1000, 1200, 1400, 1600]
          03 expensesData = [800, 900, 1000, 1100]
          04 sales = pd.Series(salesData, index = ['Q1_2023', 'Q2_2023', 'Q3_2023', 'Q4_2023'])
          05  expenses = pd.Series(expensesData, index = ['Q1_2023', 'Q2_2023', 'Q3_2023',
              'Q4_2023'])
          06 profit = sales - expenses
          07 print("Profit over four quarters: ")
          08 print(profit)
        output:
              Profit over four quarters:
              Q1_2023    200
              Q2_2023    300
              Q3_2023    400
              Q4_2023    500
              dtype: int64

        Example 2: Daily total sales across two different stores
        Suppose we have two Series that contain the daily sales of two different stores of a company for the last week. We can
        calculate the daily total sales for each day using the "+" operator as follows:
          01 import pandas as pd
          02 sales1 = [1000, 1200, 1400, 1600, 1800, 2000, 2000]
          03 sales2 = [8000, 1000, 1200, 2400, 1600, 1800, 2200]
          04 days = ['Day1', 'Day2', 'Day3', 'Day4', 'Day5', 'Day6', 'Day7']

          05 store1Sales = pd.Series(sales1, index = days)
          06 store2Sales = pd.Series(sales2, index = days)
          07 totalSales = store1Sales + store2Sales

          08 print(totalSales)
        output:
              Day1    9000
              Day2    2200
              Day3    2600
              Day4    4000
              Day5    3400

          16   Touchpad Informatics Practices-XII
   25   26   27   28   29   30   31   32   33   34   35