In this article, you will get important QnA Pandas Series IP Class 12. For all of these questions, consider that Pandas and NumPy modules have been imported as:

import pandas as pd
import numpy as np

Watch this video before starting this article to understand about series:

IP Class 12 Pandas Important Questions – Very Short and Short Answer Questions

Let’s start the article QnA Pandas Series IP Class 12 with very short and short answer questions.

[1] Identify the Pandas Data Structure: 

  1. Represents a single-column – Series
  2. Heterogeneous  2D Data – DataFrame

[2] Which module is required to be installed to create a series?

Ans.: Python requires installing the pandas module to create series.

[3] Write the statement to import pandas for the python program to create a series.

Ans.: Pandas can be imported into python program using the following two ways:

  1. import pandas as pd
  2. from pandas import *

[4] Who developed the module pandas? When and Where?

Ans.: The pandas module was developed by Wes McKinney in 2008 at AQR Capital Management.

[5] Which languages are used to develop the module pandas?

Ans.: The developer used Python, Cython and C language to develop the Pandas module. 

[6] What is the full form of Pandas?

Ans.: Pandas stands for Panel Data System.

[7] What was the main motive behind developing the pandas module?

Ans.: The main motive behind developing the pandas was there was a requirement for high-performance, flexible tools to perform quantitative analysis on financial data. 

[8] Write any four characteristics/features of the Pandas module.

Ans.: 

  1. Pandas support multiple formats to analyze data easily
  2. It offers the best tool for input and output data
  3. It also provides easy filtering data according to conditions
  4. Allows to set a subset of data from the given data set
  5. It also supports the group through and statistics functions

[9] Explain the following series attributes with an example:

  1. index – Returns the indices along with their datatype of specified series.
    • Ex.: s.index
    • If s is a series object holds the values 11,12,13 and indices has been given as [‘A’,’B’,’C’], then the output will be Index([‘A’,’B’,’C’],dtype=’Object’])
  2. values – Returns the values in form of the list from the specified series
    • Ex.: s.values
    • The output will be : array([11,12,13],dtype=int64)
  3. dtype – Returns the data types of the values given in the specified series
    • Ex.: s.dtype
    • The output will be dtype(‘int64’)
  4. nbytes – Returns the n no. of bytes of the given data values from the specified series
    • Ex.: s.nbytes
    • The output will be 24, 8 Bytes for each value
  5. size: Returns the size (no. of elements) for the specified series
    • Ex.: s.size
    • The output will be 3
  6. hasnans: Returns True if the series has any NaN value otherwise False
    • Ex. s.hasnans
    • The output will be False
  7. index.name: Used to assign new index name to the existing index
    • Ex. s.index.name=’NewIndex’
    • print(s.index.name)
    • The output will be : ‘NewIndex’
  8. shape: Returns the tuple of rows for the specified series
    • Ex. s.shape
    • The output will be : (3,)
  9. ndim: It returns the number of dimensions of the specified series. In series, it is always 1
    • Ex. s.ndim
    • The output will be : 1
  10. empty: It returns True if the series is empty otherwise False
    • Ex. s.empty
    • The output will be: False

QnA Pandas Series IP Class 12 – Output  Questions

1. Consider the following series object Named ‘Ser’:
    0       578
    1        235
    2       560
    3       897
    4       118
 
What will be the output of following statements?:
i) print(ser.index)     –> RangeIndex(start=0, stop=5, step=1)
 
ii) print(ser.values)  –> array([578, 235, 560, 897, 118], dtype=int64)
 
iii) print(ser.shape) –> (5,)     
 
iv) print(ser.size)      –> 5
 
v) print(ser[3])          –> 897
 
vi) print(ser.hasnans)  –> False
 
vii) print(ser.empty)    –> False
 
viii) print(ser.ndim)  –> 1
 
ix) ser[2]= 999                        
      ser[4]=ser[3]+4                     
      print(ser[2],ser[4]) –>   999 901                                 
 
x) import pandas as pd
       ser=pd.Series([578,235,560,897,118])
       print(ser[2:])
       print(ser[:3])
       print(ser[: :-1]) 
Ans: 
2 560
3 897
4 118
dtype: int64
0 578
1 235
2 560
dtype: int64
4 118
3 897
2 560
1 235
0 578
dtype: int64
 
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)
   Ans:
Difference:
Apple 50
Mango 20
Banana 20
Grapes 20
dtype: int64
Apple 200
Mango 180
Banana 130
Grapes 160
dtype: int64
 
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])
Ans.
0 True
1 True
2 False
3 False
4 False
5 True
6 True
7 True
8 True
9 False
dtype: bool
 
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)
Ans.:
0 1
1 3
2 5
3 7
4 9
dtype: int64
0 1
1 3
2 5
3 7
4 9
5 1
6 3
7 5
8 7
9 9
10 1
11 3
12 5
13 7
14 9
dtype: int64
 
5. ser = pd.Series(range(1,10))
    ser.head(4)
    ser.tail()
    ser.head()
Ans.:
0 1
1 2
2 3
3 4
dtype: int64
4 5
5 6
6 7
7 8
8 9
dtype: int64
0 1
1 2
2 3
3 4
4 5
dtype: int64
 
6.
import pandas as pd
l=[4,6,8]
s1=pd.Series(l)
s2=pd.Series(l*2)
s3=pd.Series(s1*2)
print(“Series1:”)
print(s1)
print(“\nSeries2:”)
print(s2)
print(“\nSeries3:”)
print(s3)  
 
Output:

Series1:
0 4
1 6
2 8
dtype: int64

Series2:
0 4
1 6
2 8
3 4
4 6
5 8
dtype: int64

Series3:
0 8
1 12
2 16
dtype: int64

7.

import pandas as pd
l=[‘Amit’,’Bhargav’,’Charmi’,’Divya’,’Falguni’,’Gayatri’]
s=pd.Series(l)
print(“Output1:”)
print(s[:3])
print(“\nOutput2:”)
print(s[3:3:3])
print(“\nOutput3:”)
print(s[-3:])
print(“\nOutput4:”)
print(s[:-4:-1])

Output:

Output1:
0 Amit
1 Bhargav
2 Charmi
dtype: object

Output2:
Series([], dtype: object)

Output3:
3 Divya
4 Falguni
5 Gayatri
dtype: object

Output4:
5 Gayatri
4 Falguni
3 Divya
dtype: object

 
8.
import pandas as pd
s=pd.Series({1:11,2:22,3:99,4:44,5:36})
print(s[s%2==0])
 
Output:
2 22
4 44
5 36
dtype: int64
 
9.
import pandas as pd
m=pd.Series(data=[22,17,23,24,18,25])
print(m[m>20])
 
Output:
0 22
2 23
3 24
5 25
dtype: int64
 
10.
import pandas as pd
s=pd.Series([55,44,33,22,11])
print(s[-1:])
 
Output:
4 11
dtype:int64
In the next section of QnA Pandas Series IP Class 12 we will see error-based questions:

Error Questions (Assume that all required packages are imported)

1. ser = pd.series(range(4))
    print(ser)
Ans.: In the statement pd.series, s of series should be capital.
 
2. ser = pd.Series(11,22,33,55, index = range(3))
Ans.: The values (11,22,33,55) in series should be passed in a list form.
 
3. l = np.array([‘C’,’C++’,’Java’,’Python’])
    s = pd.Series(l,index=[501,502,503,504])
    print(s[501,502,504])
Ans. Line no. 3, the index should be enclosed with more square brackets. 
 
4. ser = pd.Series(range(1,12,2),index=list(‘pqrst’))
Ans. Indexes are not provided properly. The elements of series are 6, where indexes are 5.
 
The next section of QnA Pandas Series IP Class 12 is based on Conceptual Questions, have a look:
 

(1) What are pandas? Explain in detail.

  • Pandas word derived from PANel Data System.
  • It becomes popular for data analysis.
  • It provides highly optimized performance with back end source code is purely written in C or Python.
  • It makes a simple and easy process for data analysis. 

(2) List out common data structures supported by Pandas.

  • Series
  • Dataframe

(3) What is a panda series? Explain with a suitable example.

  • Series is one-dimensional data structure. 
  • It contains an array of data.
  • Series contains two main components: An Index, An indexed associated with an arrayImportant QnA Pandas Series IP Class 12

(5) How to create an empty series? Explain with a suitable example.

  • To create an empty series use Series() method with Pandas object. 
  • Observe this code:
import pandas as pd
ser = pd.Series()

(6) How to create a series with an example: A python sequence, NumPy Array, A dictionary, A scalar value

  • A python sequence
import pandas as pd
ser=pd.Series(range(5))
  • NumPy Array
import pandas as pd
import numpy as np
arr = np.arange(1,10,1)
ser = pd.Series(arr)
  • A scalar value
import pandas as pd
ser = pd.Series(5,range(1,5))

(7) Name the function that displays the top and bottom elements of a series. Explain with an example.

Ans.: The functions that display the top and bottom n elements of a series are head() and tail() respectively. 

Example:

import pandas as pd

s=pd.Series([2,3,4,5,6,7,8])

print(s.tail(3))

print(s.head(3))

By default, this function will display 5 elements. 

(8) What is the use of the drop() and reindex() method? Explain with an example.

Follow this link for answers:

Download Free PDF easy notes for Data handling using Pandas-I Series Class 12

 
In the next section of QnA Pandas Series IP Class 12, do practice for program-based questions:
 
1. Write a program to store a population of 4 cities with an index of the previous 4 years. Write functions to do the following:
    i) Print the average population of the recent two years.
   ii) Print the grand total of populations.
  iii) Print the highest population.
  iv) Print the difference between the first year and last year.
    v) Delete entry of one year from the series.
Ans.: 
import pandas as pd
popu=[]
years=[]
y=2021
for year in range(y,y-4,-1):
     p=int(input(“Enter the population:”))
     popu.append(p)
     years.append(year)
 
#Creating Series
s=pd.Series(popu,index=years)
 
#Print Average
print(“Average population of recent two years:”,s.head(2).index,s.head(2).mean())
 
#Sum of population
print(“Sum of population of all cities:”,s.sum())
 
#Maximum
print(“Maximum population:”,s.max())
 
#Defference First year and last year
print(“Difference between First year and Last Year:”,s[2021]-s[2018])
 
#Delete data for specific year
yr=int(input(“Enter year to delete:”))
s=s.drop(labels=yr)
print(“Series Data After Deletion:”)
print(s)
 
2. Write a program to store employees’ salary data for one year. Write functions to do the following: 
   i) Display salary data for every 4th month.
  ii) Display salary of any one month.
 iii) Apply increment of 10% into salary for all values.
 iv) Give 2400 arrear to employees in April month.
Ans.:

import pandas as pd
d={‘Jan’:45000,’Feb’:44808,’Mar’:44302,’Apr’:45000,’May’:44808,’June’:43521,
‘July’:44785,’Aug’:44856,’Sept’:46325,’Oct’:45878,’Nov’:45368,’Dec’:45778}

s=pd.Series(d)

#Salary of data for every 4 month
print(“Salary of every 4th month:”)
print(s[::4])

#Display the salary of a specific month
m=input(“Enter month to display salary:”)
if m in s.index:
 print(“Month:”,m,”Salary:”,s[m])
else:
 print(“Enter valid month”)

#Increment 10% for all months
s=s+(s*0.10)
print(s)

#Add arrear for april
s[‘Apr’]=s[‘Apr’]+2400
print(“Salary with Arrear”,s[‘Apr’])

  
3. Write a program to create a series using numpy array that stores the capitals of some countries. Give Country name as an index of series. 
Ans.:
import pandas as pd
import numpy as np
l=np.array(['Kabul','Dhaka','Ottawa','Beijing','Paris'])
s=pd.Series(l,index=['Afghanistan','Bangladesh','Canada','China','France'])

4. Write a program to create a series using a dictionary that stores a number of students in each class from 9 to 12 of a school. Store the class in roman as index of series.
Ans.:
import pandas as pd
d={'IX':238,'X':225,'XI':154,'XII':152}
s=pd.Series(d)
print(s)
 
Watch this video for more understanding of  Pandas Series IP Class 12 in one shot. 

Practical List of IP class 12 Programs with solutions

Click here to access all the contents of IP class 12:

IP Class 12

3 thoughts on “Important QnA Pandas Series IP Class 12”

Leave a Reply