Page 42 - Informatics_Practices_Fliipbook_Class12
P. 42

Ans.  a. import numpy as np
                import pandas as pd
                EngAlph=pd.Series(['a','b','c','d','e','f','g','h','i','j','k','l','m',
                'n','o','p','q','r','s','t','u','v','w','x','y','z'])
                print("Size:",EngAlph.size)
                print("Dimension:",EngAlph.ndim)
                print("Values:",EngAlph.values)

                vowels=pd.Series(0,index=['a','e','i','o','u'])
                print("Size:",vowels.size)
                print("Dimension:",vowels.ndim)
                print("Values:",vowels.values)

                dict1={"Samir":1,"Manisha":2,"Dhara":3,"Shreya":4,"Kusum":5}
                friends=pd.Series(dict1)
                print("Size:",friends.size)
                print("Dimension:",friends.ndim)
                print("Values:",friends.values)

                MTseries=pd.Series(dtype=int)
                print("Size:",MTseries.size)
                print("Dimension:",MTseries.ndim)
                print("Values:",MTseries.values)

                monthDays=np.array([31,28,31,30,31,30,31,31,30,31,30,31])
                month=pd.Series(monthDays,index=np.arange(1,13))
                print("Size:",month.size)
                print("Dimension:",month.ndim)
                print("Values:",month.values)
              b.  MTseries.rename("SeriesEmpty", inplace = True)
              c.  friends.index.name = "Fname"
                month.index.name = "MonthNo"
              d.  print(friends.iloc[2:0:-1])
              e.  print(EngAlph.iloc[4:16])
              f.  print(EngAlph.head(10))
              g.  print(EngAlph.tail(10))
              h.  print(MTseries)
           5.  Using the Series created in Question 2, write commands for the following:
              a.  Display the names of the months 3 through 7 from the Series MonthDays.
              b.  Display the Series MonthDays in reverse order.

         Ans.  a. import numpy as np
                import pandas as pd
                monthDays=np.array([31,28,31,30,31,30,31,31,30,31,30,31])
                month=pd.Series(monthDays,index=["Jan","Feb","Mar","Apr","May","June",


          28   Touchpad Informatics Practices-XII
   37   38   39   40   41   42   43   44   45   46   47