Skip to main content

QUESTIONS BASED ON PANDAS SERIES | IP

 QUESTIONS BASED ON PANDAS SERIES

GRADE XII

1.Given the following Series1

A   100

B   200

C   300

D   400

E   500

Write the command to create above Series and then double the value in series and store in another series named Series2

Sol:

import pandas as pd 

Series1=pd.Series([100,200,300,400,500],index=['A','B','C','D','E']) 

Series2=Series1*2 

print(Series1) 

print(Series2)

2. State whether True or False

a. A series object is size mutable.

b. A Dataframe object is value mutable

Sol:

a. A series object is size mutable. (False) 

b. A Dataframe object is value mutable (True)

3. Consider a given Series , Series1:

200 700

201 700

202 700

203 700

204 700

Write a program in Python Pandas to create the series and display it.

Sol:

import pandas as pd 

Series1=pd.Series(700,index=range(200,205)) 

print(Series1)

4.Consider the following Series object, s

IP          95

Physics     89

Chemistry   92

Math        95

i. Write the Python syntax which will display only Physics.

ii. Write the Python syntax to increase marks of all subjects by 10.

Sol:

import pandas as pd 

s=pd.Series([95,89,92,95],index=['IP','Physics','Chemistry','Math']) 

print(s.index[0]) 

s=s+10 print(s)

5. Consider a given series : SQTR

QTR1   50000

QTR2   65890

QTR3   56780

QTR4   89000

QTR5   77900

Write a program in Python Pandas to create and display the series.

Sol:

import pandas as pd 

val1=[50000,65890,56780,89000,77900] 

idx=['QTR1','QTR2','QTR3','QTR4','QTR5'] 

SQTR=pd.Series(val1,index=idx) 

print(SQTR)

6. What will be the output produced by the following programming statements 1 & 2?

import pandas as pd

S1=pd.Series(data=[31,41,51])

print(S1>40)          -->Statement1

print(S1[S1>40])   -->Statement2

Sol:  Execute & see the output


7.Given two series S1 and S2

S1            S2

A  39       A  10

B  41       B  10

C  42       D  10

D  44       F  10

Find the output for following python pandas statements?

a. S1[ : 2]*100

b. S1 * S2

c. S2[ : : -1]*10

Sol: Execute & see the output

8.Given the following Series S1 and S2:

S1         S2

A   10 A   5

B   20 B   4

C   30 C   6

D   40 D   8

Write the command to find the multiplication of series S1 and S2

Sol:

import pandas as pd 

S1=pd.Series([10,20,30,40],index=['A','B','C','D']) 

S2=pd.Series([5,4,6,8],index=['A','B','C','D']) 

print(S1*S2)

9. Consider the following Series object, “company” and its profit in Crores

TCS           350

Reliance    200

L&T          800

Wipro       150

i. Write the command which will display the name of the company having profit>250.

ii. Write the command to name the series as Profit.

Sol:

import pandas as pd 

profit=[350,200,800,150] 

idx=['TCS','Reliance','L & T','Wipro'] 

company=pd.Series(profit,index=idx) 

print(company[company>250]) 

company.name="Profit" 

print(company)

10.What will be the output of following code- import pandas as pd

s1=pd.Series([1,2,2,7,’Sachin',77.5])

print(s1.head())

print(s1.head(3))


11. What are the purpose of following statements-

1. df.columns

2. df.iloc[:, :-5]

3. df[2:8]

4. df[:]

5. df.iloc[: -4, : ]


12. Given a Pandas series called Sample, the command which will display the last 3 rows is .

a. print(Sample.tail(3))

b. print(Sample.Tail(3))

c. print(Sample.tails(3)

d. print(Sample.Tails(3))


13. What will be the output of the following code?

import pandas as pd

s = pd.Series(6,index=range(0,5))

print(s)


14. If series s1 is having following data,

1      6

3      1

5      3

7      5

9      4

11    8

13    7

17    6

19    7

What would be the result of the command print(s1[3:6])?


15. What will be the output of the following code?

import pandas as pd

import numpy as np

s = pd.Series(np.arange(10,50,10))

print(s)

print (s.ndim)

print(s.shape)

print(len(s))


16. Predict the output of the following code.

import pandas as pd

import numpy as np

data = {'one':'a','two':'b','three':'c'}

s=pd.Series(data)

print(s)

print(s.size)


17. Create a Series object S1 using a python sequence [2,4,6,8] and default indices.

Sol:

import pandas as pd 

data = range(2,10,2) 

S1=pd.Series(data) 

print(S1)

18 . Write the output of the following code fragment.

import pandas as pd

s2=pd.Series(["i","am", "a","student"])

print(s2)


19. Write the output of the following code fragment.

import pandas as pd

s1=pd.Series(200,index=range(2,13,2))

print(s1)


20. Consider a series object s10 that stores the number of students in each section of class 12 as shown below. First two sections have been given task for selling tickets @ Rs.100/- per ticket as a part of social experiment. Write code to create the series and display how much section A and B have collected.

A      39

B      31

C     32

D     34

E     35

Sol:

import pandas as pd 

import numpy as np  

S10=pd.Series([39,31,32,34,35],index=['A','B','C','D','E'], dtype=np.float32) 

print("Amount collected by Section A and B (in Rs.)") 

print(S10.head(2)*100)


21.Consider the series s4 as given below

0     2.50

1     17.45

2     20.25

3     87.25

4     33.76

What will be the output after executing the following:

S4[0]=1.75

S4[2:4]= -23.74

print(S4)


22. Consider the series s1 and s2 and s3-

S1              S2                S3

0   10         0   5              a   3

1   20         1  10             b   6

2   30         2  15             c   9

3   40         3   20            d  10

4   50         4   25            e   11

                  5   30

                  6   35

Now find the output of the following-

i) print(S1+S2)

ii) print(S1*S3)

iii) print(S1-S2)


23.What will be the output of the following:

import pandas as pd

D={'a':10,'b':11,'c':12}

S=pd.Series(D,index=['b','c','d','a'])

print(S)


24. What is the output of the following program:

import pandas as pd

import numpy as np

data=np.array(['Mon','Tue','Wed','Thu','Fri','Sat','Sun'])

s=pd.Series(data, index=[101,102,103,104,105, 106,107])

print(s[[103,105,107]])


25. What is the output of the following program:

import pandas as pd

import numpy as np

data=np.array(['Mon','Tue','Wed','Thu','Fri','Sat','Sun'])

s=pd.Series(data)

print(s[:4])

print(s[-4:])

Comments

Popular posts from this blog

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...

GRADE XII CS - VIVA QUESTIONS

  VIVA QUESTIONS GRADE XII CS Dear All Be thorough with your project and practical files, as the viva can be asked from anywhere. Stay calm, don’t get nervous, and be confident in front of the examiner. 1. Tell me about your project. 2. Which concepts you have used for your project? 3. What do you mean by front end and back end? How they are important in developing any such projects? 4  Mention the modules and built-in functions you have used in your project. 5. Which real world problems are solved by your project? 6. Explain the most important feature of your project. 7. Name a few mutable data types of python. Lists, Sets, and Dictionaries 8. Name a few immutable data types of python. Strings, Tuples, Numeric 9. Name ordered and unordered data type of python. Ordered – String, List, Tuples Unordred – Set, Dictionaries 10. What is the significance of a pass statement in python? pass is no operation python statement. This is used where python requires syntax but logic requires...