Page 197 - Robotics and AI class 10
P. 197

tail(n)     Returns the last n members of the series.  import pandas as pd
                            If n is not specified then by default the  friends =
                            last five members are displayed.       pd.Series(["Rohan","Susan","James",
                                                                   "Riya","Sumit","Abhinav","Vihaan"]
                                                                   index[11,22,33,44,55,66,77])
                                                                   print(friends.tail())
                                                                   33    James

                                                                   44    Riya
                                                                   55    Sumit
                                                                   66    Abhinav
                                                                   77    Vihan
                                                                   dtype: object
                count()     It counts the total non NaN values in a  import pandas as pd
                            series                                 friends                                     =

                                                                   pd.Series(["Rohan","Susan","James",
                                                                   "Riya","Sumit","Abhinav","Vihaan"]
                                                                   index[11,22,33,44,55,66,77])
                                                                   print(friends.count())
                                                                   7
            DataFrames
            A DataFrame is a two-dimensional labelled heterogeneous data structure that contains rows and columns. It has
            both a row and column index. The data arranged in the form of a row and a column resembles the data arranged
            in a tabular form in a table of a database.
            Creating a DataFrame
               • Creating an empty DataFrame

              import pandas as pd
              Emp = pd.DataFrame() print(Emp)

              Empty DataFrame
              Columns: []
              Index: []
               • Creating a DataFrame from Numpy Array
               import numpy as np

              import pandas as pd
              a1 = np.array([10,20,30])
              a2 = np.array([11,22,33])
              f1=pd.DataFrame(a1)
              f2=pd.DataFrame([a1,a2])
              print(f1)
              print(f2)
                     0
              0      10


                                                         Introduction to Data and Programming with Python  195
   192   193   194   195   196   197   198   199   200   201   202