0% found this document useful (0 votes)
242 views

Pandas Series

The document contains examples of using Pandas Series methods and operations. It demonstrates printing Series attributes like index, values and shape. It shows indexing, slicing, arithmetic operations and comparisons on Series. Conditional logic is applied to filter Series values. The document also contains examples of iterating to populate a Series and examples of errors that may occur.

Uploaded by

sofia gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
242 views

Pandas Series

The document contains examples of using Pandas Series methods and operations. It demonstrates printing Series attributes like index, values and shape. It shows indexing, slicing, arithmetic operations and comparisons on Series. Conditional logic is applied to filter Series values. The document also contains examples of iterating to populate a Series and examples of errors that may occur.

Uploaded by

sofia gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Consider the following series object Named ‘Ser’:


    0       578
    1        235
    2       560
    3       897
    4       118
What will be output of following statements?:
i) print(ser.index)     ii) print(ser.values)     iii)
print(ser.shape)     iv) print(ser.size)    v) print(ser[3])
 
vi) ser[2]= 999                        vii) print(ser[2:])
      ser[4]=ser[3]+4                       print(ser[0:3])
      print(ser)                                   print(ser[: :-1]
 
2. fruits = [‘Apple’,’Mango’, ‘Banana’, ‘Grapes’]
    r2019 = pd.Series([100,80,30,60], index = fruits)
    r2020 = pd.Series([150,100,50,80], index = fruits)
    print (“Difference:”)
    print (r2020 – r2019)
    r2020 = r2019 + 100
    print (r2020)
  
3. ser =
pd.Series([5987,5634,3450,2500,1500,7899,6432,8756,
9123,4400])
    print(ser>5000)
    print(ser==1500 or ser==1500)
    print(ser[ser<5000])
 
4. l=[]
    for i in range(1,11,2):
        l.append(i)
    ser=pd.Series(l)
    print(ser)
    ser1=pd.Series(l*3)
    print(ser1)
 
5. ser = pd.Series(range(1,10))
    ser.head(4)
    ser.tail()
    ser.head()
 
In the next section of QnA Pandas Series IP Class 12 we will see error-
based questions:
Error Questions
1. ser = pd.series(range(4))
    print(ser)
 
2. ser = pd.Series(11,22,33,55, index = range(3))
 
3. l = np.array([‘C’,’C++’,’Java’,’Python’])
    s = pd.Series(l,index=[501,502,503,504])
    print(s[501,502,504])
 
4. ser = pd.Series(range(1,12,2),index=list(‘pqrst’))
 
 
 

You might also like