Page 456 - AI Ver 3.0 class 10_Flipbook
P. 456

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

               count()     It counts the total non
                                                     [1]:   import pandas as pd
                           NaN values in a 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


              Different ways to create a DataFrame are as follows:
                 • Creating an empty DataFrame
                 [1]:   import pandas as pd
                        Emp = pd. DataFrame ()
                        print(Emp)

                        Empty DataFrame
                        Columns: []
                        Index: []

                 • Creating a DataFrame from Numpy Array
                 [1]:   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
                        1  20
                        2  30
                            0   1   2
                        0  10  20  30
                        1  11  22  33



                    454     Touchpad Artificial Intelligence (Ver. 3.0)-X
   451   452   453   454   455   456   457   458   459   460   461