Page 230 - AI Ver 1.0 Class 10
P. 230

Sorting the array   ARR.sort()     a = np.array([12,4,-10,23,29,15,                [-14 -10  -1   4  12
                                                  -1,45,33,37,-14]) #Creating a 1-D               15  23  29  33  37
                                                  Numpy array                                     45]
                                                  print(np.sort(a)) #Printing the                 [[ -9   5   9  12  18]
                                                  sorted numpy array
                                                                                                  [-10  -5   3  10  11]]
                                                  #We can also sort array row wise
                                                                                                  [[ -9   5   3  -5 -10]
                                                  and column wise!
                                                  b = np.array([[-9,5,18,9,12],                    [ 10  11  18   9  12]]
                                                  [10,11,3,-5,-10]]) #Creating a 2-D
                                                  Numpy array

                                                  print(np.sort(b, axis = 1)) #Axis =
                                                  1performs the sorting function row-
                                                  wise

                                                  print(np.sort(b, axis = 0)) #Axis
                                                  = 0 performs the sorting function
                                                  columns-wise


              Pandas

              Panda is an open-source Python library used for data manipulation and data analysis. It provides a very strong
              feature of using three important data structures— Series (1-dimensional), DataFrame

              (2-dimensional) and Panel (3-dimensional) for smooth processing and analysis of data, regardless of its origin.
              The data actually need not be labelled at all to be placed into a Pandas data structure.
              Pandas was created by Wes McKinney in 2008 and has derived its name from both “Panel Data”, and “Python
              Data Analysis” which means using a statistical method of analysing the data taken from the observations about
              different cross sections over the period of time.

              Pandas libraries are built on NumPy so to work in Pandas the prerequisite is to get familiar with NumPy and
              install it. Data required for Pandas can be taken as:
                 • Tabular data with heterogeneously-typed columns, as in an SQL table or Excel spreadsheet.

                 • Ordered and unordered (not necessarily fixed-frequency) time series data.
                 • Arbitrary matrix data (homogeneously typed or heterogeneous) with row and column labels.

                 • Any other form of observational/statistical data sets.


              File Access Using Pandas
              Pandas can be accessed by using import:

              import pandas as pd
              To save the csv file into a variable:

              s = pd.read_csv(“Student data.csv”)
              To print the first five rows of the file:

              print (s.head(5))


                        228   Touchpad Artificial Intelligence-X
   225   226   227   228   229   230   231   232   233   234   235