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:
Watch this video before starting this article to understand about series:
Topics Covered
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:
- Represents a single-column – Series
- 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:
- import pandas as pd
- 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.:
- Pandas support multiple formats to analyze data easily
- It offers the best tool for input and output data
- It also provides easy filtering data according to conditions
- Allows to set a subset of data from the given data set
- It also supports the group through and statistics functions
[9] Explain the following series attributes with an example:
- 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’])
- 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)
- dtype – Returns the data types of the values given in the specified series
- Ex.: s.dtype
- The output will be dtype(‘int64’)
- 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
- size: Returns the size (no. of elements) for the specified series
- Ex.: s.size
- The output will be 3
- hasnans: Returns True if the series has any NaN value otherwise False
- Ex. s.hasnans
- The output will be False
- 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’
- shape: Returns the tuple of rows for the specified series
- Ex. s.shape
- The output will be : (3,)
- 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
- 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
ser=pd.Series([578,235,560,897,118])
print(ser[2:])
print(ser[:3])
print(ser[: :-1])
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
Apple 50
Mango 20
Banana 20
Grapes 20
dtype: int64
Apple 200
Mango 180
Banana 130
Grapes 160
dtype: int64
1 True
2 False
3 False
4 False
5 True
6 True
7 True
8 True
9 False
dtype: bool
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
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
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)
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
4 44
5 36
dtype: int64
2 23
3 24
5 25
dtype: int64
Error Questions (Assume that all required packages are imported)
(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 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 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
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())
#Maximumprint(“Maximum population:”,s.max())
#Defference First year and last yearprint(“Difference between First year and Last Year:”,s[2021]-s[2018])#Delete data for specific yearyr=int(input(“Enter year to delete:”))
s=s.drop(labels=yr)
print(“Series Data After Deletion:”)
print(s)
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’])
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'])
import pandas as pd
d={'IX':238,'X':225,'XI':154,'XII':152}
s=pd.Series(d)
print(s)
Click here to access all the contents of IP class 12:
Hello sir good evening
Can you provide the assignment answers
Yes answers will be also, published. For explanation subscribe youtube channel -> tutorialaicsip
Subscribed but where is answers