Page 261 - AI Computer 10
P. 261

Now, let us learn how to create a series, a one-dimensional array which can store data of any type in Jupyter
        Notebook. To create a Pandas series, you should follow the given steps:
         u Import the Pandas package with the help of Python’s import command:

                       import pandas as pd
             Here, ‘pd’ is used to refer to the pandas library.

         u You can create the Series by invoking the pd.Series() method. In this method, you can define an array like:
                       initial_series = pd.Series([10,20,30,40,50])
         u Display the content of Series with the help of the Print command such as:
                       print(initial_series)
        Hence, we can create a Pandas series by the following lines of code:










        Here, you can see that two columns are displayed, out of which the first column denotes the indexes for the
        elements and the second denotes the elements of the series.
        Pandas DataFrame can be seen as a table because it is a two-dimensional data structure. It organizes data into
        rows and columns. In Python, two different methods are available to create Pandas DataFrame.
         u By typing the values in Python itself to create the DataFrame: You can easily create a dataframe in Python
             by typing the values with the help of the following syntax:
              import pandas as pd
              data = {‘First Column Name’:  [‘First value’, ‘Second value’,...],
                      ‘Second Column Name’: [‘First value’, ‘Second value’,...],
                       ....
                      }
              df = pd.DataFrame (data, columns = [‘First Column Name’,’Second Column Name’,...])
              print(df)
        Let us understand the above syntax with the help of the example given below:

              import pandas as pd
              jeans = {‘Brand_Name’: [‘Killer’,’Allen Solly’,’Denim’],
                      ‘Price’: [20000,30000,80000],
                       ‘Discounted_Price’: [10000,25000,27000]
                      }
              data_frame = pd.DataFrame(jeans, columns = [‘Brand_Name’, ‘Price’, ‘Discounted_
              Price’])
              print(data_frame)
        The output of the above lines of code is shown in the snapshot given below:














                                                                                                             127
                                                                                                             127
   256   257   258   259   260   261   262   263   264   265   266