Page 201 - Touhpad Ai
P. 201

Pandas performs better with datasets containing 500,000 rows or more, while NumPy
                    BRAINY                    excels with datasets of 50,000 rows or fewer. When it comes to
                      FACT             indexing, Pandas series are significantly slower than NumPy arrays, which have
                                                             very fast indexing capabilities.





                    Program 4: To create a series from a list

                   import pandas as pd
                   # Creating a series from a list
                   data = [1, 2, 3, 4, 5]
                   series = pd.Series(data)
                   print(series)
                   Output:

                   0    1
                   1    2
                   2    3
                   3    4
                   4    5
                   dtype: int64

                 DataFrames
                 In pandas, a DataFrame is a two-dimensional labelled data structure, similar to a table in a spreadsheet or a database.
                 It consists of rows and columns, where each column can have a different data type (like integers, floats, strings, etc.).
                 Some examples of a DataFrame are: class’s result, menu items in a restaurant, or a train's reservation chart, etc.

                                            Index      Name       Test 1     Test 2      Test 3
                                             0       Amit           92         75         79
                                              1      Yash           81         85         84
                                              2      Rohan          76         72         85
                                              3      Devesh         78         83         90
                                              4      Nihar          92         87         87

                 Creating a DataFrame

                 There are several ways depending on the data source and structure by which you can create a dataframe in Pandas.
                 Some most common method for creating a DataFrame are:
                 u  From lists or arrays: You can create a DataFrame by passing a list or a NumPy array to the pd.DataFrame()
                    constructor. Each element of the list or array will be treated as a row.

                    Program 5: To create a DataFrame using lists or arrays
                   import pandas as pd

                   data = [[1, 'Mayur', 25],
                      [2, 'Esha', 30],
                      [3, 'Vedant', 28]]

                                                                      Theoretical and Practical Aspects of Data Processing  199
   196   197   198   199   200   201   202   203   204   205   206