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

• Creating series using labelled index


                    [1]:  import pandas as pd
                          friends = pd. Series(["Rohan","Susan","James"], index=[11, 22,33])
                          print(friends)

                          11    Rohan
                          22    Susan
                          33    James
                          dtype: object

                    • Creating a Series from a Python list


                    [1]:  import pandas as pd
                          cities = ['Delhi', 'Mumbai', 'Chennai', 'Kolkata' ]
                          s2 = pd.Series(cities)
                          print(s2)

                          0      Delhi
                          1     Mumbai
                          2    Chennai
                          3    Kolkata
                          dtype: object

                    • Creating series using labelled index

                    [1]:  import pandas as pd
                          month=["June", "August", "October", "December"]
                          s4 = pd.Series(month, index = [6,8,10,12])
                          print(s4)
                          6         June
                          8       August
                          10     October
                          12    December
                          dtype: object

                    • Creating a Series from a Python dictionary

                    [1]:  import pandas as pd
                          dict={6:"June", 8: "August", 10: "October", 12: "December"}
                          s5 = pd.Series(dict)
                          print(s5)

                          6         June
                          8       August
                          10     October
                          12    December
                          dtype: object

                 Accessing the Element of the Series


                 The elements can be accessed using either positional index or labelled index.



                                                                                    Advance Python (Practical)  451
   448   449   450   451   452   453   454   455   456   457   458