Important QnA Pandas Series IP Class 12

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

Topics Covered

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)Â  –> [578 235 560 897 118]Â  Â
Â
iii) print(ser.shape) –> (5,)Â  Â  Â
Â
iv) print(ser.size)Â  Â  Â  –> 5
Â
v) print(ser[3])Â  Â  Â  Â  Â  –> 897
Â
vi) ser[2]= 999Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â  Â Â
Â  Â  Â  ser[4]=ser[3]+4Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
Â  Â  Â  print(ser[2],ser[4]) –>Â  Â 999 901Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â
Â
vii) import pandas as pd
Â  Â  Â  Â ser=pd.Series([578,235,560,897,118])
Â  Â  Â  Â print(ser[2:])
Â  Â  Â  Â print(ser[0: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.tail()
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
Â
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 capitalized.
Â
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) How to use pandas library in a program? Illustrate the answer with an example.

• To use pandas libary in the program user need to import the pandas package.Â
• For example, import pandas as pd

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

• Series is one dimensional data structure.Â
• It contain an array of data.
• Series contains two main components: An Index, An indexed associated with array

(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 pdser = 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 pdser=pd.Series(range(5))`
• NumPy Array
`import pandas as pdimport numpy as nparr = np.arange(1,10,1)ser = pd.Series(arr)`
• A scalar value
`import pandas as pdser = pd.Series(5,range(1,5))`

(7) Explain the attributes of the series object with an example.

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

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

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 all cities’ population.
Â  iii) Print the highest population of each city.
Â  iv) Print the difference between the first year and last year.
Â  Â  v) Delete entry of one year from the series.
Â
2. Write a program to store employees’ salary data for one year. Write functions to do the following:Â
Â  Â i) Display salary data by slicing it into 4 parts.
Â  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.
Â Â
3. Write a program to do the following:
Â  Â  i) Create an empty series.
Â  Â  ii) Modify the series with scalar value 75.
Â
Â Watch this video for more understanding of QnA Pandas Series IP Class 12.Â