Page 78 - IPP-12-2024
P. 78

1    102     Vinod  15-01-2012
            2    103   Lakhbir  05-09-2007
            3    104       NaN  17-01-2012
            4    105  Devinder         NaN
            5    106  UmaSelvi  16-01-2012

               empid     ename         Doj
            0    101    Sachin  12-01-2012
            1    102     Vinod  15-01-2012
            2    103   Lakhbir  05-09-2007
            3    104       999  17-01-2012
            4    105  Devinder         999
            5    106  UmaSelvi  16-01-2012


            Program 10.  Write a Program in Pandas to create series using pre-defined array/ create series using
            user-defined array/list/ create series using pre-defined list/create Series using Predefined
            Dictionary/create series using User-defined Dictionary/ change index in series/print head and tail
            elements/print according to index position and condition in python.
            Solution:
            import pandas as pd
            #creating series using pre-defined array
            data=['a','b','c']
            s=pd.Series(data)
            print(s)
            #creating series using user-defined array/list
            #creating an array
            ar1=list()
            n=int(input("Enter the values for an array"))
            print("Enter numbers")
            for i in range(0,n):
                num=int(input("num:"))
                ar1.append(num)
            s=pd.Series(ar1)
            print(s)
            #creating series using pre-defined list
            list=['a','b','c']
            s=pd.Series(list)
            print(s)
            list=[[0,1,2,3],['a','b','c'],["vedant","purnendu","rupali"]]
            s=pd.Series(list)
            print(s)
            #creating Series using Predefined Dictionary
            dic=({'rupali':[9826386977,'rupali@gmail.com'],
            'purnendu':[9826911972,'purnendup@gmail.com'],
            'vedant':[788990,'vedant@gmail.com']})
            s=pd.Series(dic)
            print (s)
            #creating series using User-defined Dictionary
   73   74   75   76   77   78   79   80   81   82   83