0% found this document useful (0 votes)
27 views408 pages

Series 1

Uploaded by

arjuntiw890
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)
27 views408 pages

Series 1

Uploaded by

arjuntiw890
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/ 408

Series 1

Write suitable python statement for the following .

Q1. Write a python statement to make a series of Country's Capital by using NumPy Array.

import pandas as pd

import numpy as np

array1 = np.array(["New Delhi", "Rome", "London", "Paris", "Athens"])

series1 = pd.Series(array1)

print(series1)

0 New Delhi

1 Rome

2 London

3 Paris

4 Athens

dtype: object

Q2. Write a python statement to make indexes of Capitals to their country name.

series1.index = ["India", "Italy", "England", "France", "Greece"]

print(series1)

India New Delhi

Italy Rome

England London

France Paris

Greece Athens

dtype: object
Q3. Write a query to display the 1st, 3rd and 5th capital city using boolen expression.

print(series1[[True, False, True, False, True]])

India New Delhi

England London

Greece Athens

dtype: object

Q4. Write a query to display the capital of India.

print(series1["India"])

New Delhi

Q5. Write a query to display the Capital city at 5th row.

print(series1[4])

Athens

Q6. Write a query to display the capital city of those country who are at 5th, 2nd and 3rd

position.

print(series1[5, 2, 3])

Greece Athens

England London

France Paris

dtype: object
---------------------------------------------------------------------------------------------

Series 2

Write suitable python statement for the following .

Q1. Write a python statement to make a series of monthnames and month number as their index.

import pandas as pd

data = {"January" : 1, "February" : 2, "March" : 3, "April" : 4, "May" : 5, "June" : 6,

"July" : 7, "August" : 8, "September" : 9, "October" : 10, "November" : 11,

"December" : 12

series2 = pd.Series(data)

print(series2)

January 1

February 2

March 3

April 4

May 5

June 6

July 7

August 8

September 9

October 10

November 11

December 12

dtype: int64

Q2. Display 3rd to 5th months of series series2.


print(series2[3:6])

April 4

May 5

June 6

dtype: int64

Q3. Display January to March of series series2.

print(series2["January" : "March"])

January 1

February 2

March 3

dtype: int64

Q4. Write a statement in python to print the months in reverse order.

print(series2[ : : -1 ])

December 12

November 11

October 10

September 9

August 8

July 7

June 6

May 5

April 4

March 3
February 2

January 1

dtype: int64

----------------------------------------------------------------------------------------------

Series 3

CARS_DF

Q1. Create a dictionary named car_dict

COMPANY COLOR COUNT MODEL

BMW RED 3 120

DZIRE GREEN 5 100

NANO RED 25 125

I20 GREEN 26 150

SENTRO GREEN 99 70

import pandas as pd

car_dict = { "COMPANY" : ["BMW", "DZIRE", "NANO", "I20", "SENTRO"],

"COLOR" : ["RED", "GREEN", "RED", "GREEN", "GREEN"],

"COUNT" : [3, 5, 25, 26, 99],

"MODEL" : [120, 100, 125, 150, 70]

Q2. Create a DataFrame named cars, using the Dictionary car_dict.

cars = pd.DataFrame(car_dict, index = ["C1", "C2", "C3", "C4", "C5"])

print(cars)

COMPANY COLOR COUNT MODEL

C1 BMW RED 3 120

C2 DZIRE GREEN 5 100


C3 NANO RED 25 125

C4 I20 GREEN 26 150

C5 SENTRO GREEN 99 70

Q3. Find maximum COUNT from DataFrame cars.

print(cars.COUNT.max())

99

Q4. List Cars with COUNT more than 25.

print(cars.loc[cars.COUNT > 25])

COMPANY COLOR COUNT MODEL

C4 I20 GREEN 26 150

C5 SENTRO GREEN 99 70

Q5. List COMPANY of all cars whose MODEL is between 110 to 150

print(cars.loc[cars.MODEL.isin(range(110, 150)), ["COMPANY"]])

OR

print(cars.loc[(cars.MODEL > 110) & (cars.MODEL < 150), ["COMPANY"]])

COMPANY

C1 BMW

C3 NANO

Q6. Display COMPANY of all the GREEN color cars having COUNT > 10.

print(cars.loc[(cars.COLOR == "GREEN") & (cars.COUNT > 10), ["COMPANY"]])


COMPANY

C4 I20

C5 SENTRO

Q7. Name the COMPANY having odd number of COUNT.

print(cars.loc[cars.COUNT % 2 == 1, ["COMPANY"]])

COMPANY

C1 BMW

C2 DZIRE

C3 NANO

C5 SENTRO

Q8. Insert a row after SENTRO with index ‘C6’ and data as given in the list:

[ "BALENO", "RED", 65, 23 ]

cars.loc["C6"] = [ "BALENO", "RED", 65, 23 ]

Q9. Delete the column named MODEL from the DataFrame cars.

cars = cars.drop("MODEL", axis = 1)

Updated dataframe will look like

COMPANY COLOR COUNT

C1 BMW RED 3

C2 DZIRE GREEN 5

C3 NANO RED 25

C4 I20 GREEN 26

C5 SENTRO GREEN 99
Q10. Create a new Dataframe named Green_car, by copying all the rows from the DataFrame cars

where value of COLOR column is GREEN.

df1 = cars.loc[cars.COLOR == "GREEN"]

df2 = pd.DataFrame(df1)

print(df2)

COMPANY COLOR COUNT MODEL

C2 DZIRE GREEN 5 100

C4 I20 GREEN 26 150

C5 SENTRO GREEN 99 70

---------------------------------------------------------------------------------------------

WORKSHEET - 1

PANDAS : DATA FRAME

Q1. Create the following Data Frame df

Name DOB Gender Mobile Height Weight

ADITYA PAL 01/12/2002 M 9876543210 5.8 55

PALAK AGARWAL 08/11/2002 F 9987654321 5.0 45

KULDEEP SINGH 12/02/2003 M 9998765432 5.3 48

NEHA 02/05/2003 F 9999765432 5.3 50

PRAVESH 03/05/2002 M 8885963212 5.5 54

SUMIT PACHORI 05/03/2001 M 8956664232 5.6 56

TANUSHKA 02/02/2002 F 9856472362 5.1 50

import pandas as pd

data = {"Name" : ["ADITYA PAL", "PALAK AGARWAL", "KULDEEP SINGH", "NEHA", "PRAVESH", "SUMIT
PACHORI", "TANUSHKA"],

"DOB" : ["01/12/2002" , "08/11/2002", "12/02/2003", "02/05/2003", "03/05/2002",


"05/03/2001", "02/02/2002"],
"Gender" : ["M", "F", "M", "F", "M", "M", "F"],

"Mobile" : [9876543210, 9987654321, 9998765432, 9999765432, 8885963212, 8956664232,


9856472362],

"Height" : [5.8, 5.0, 5.3, 5.3, 5.5, 5.6, 5.1 ],

"Weight" : [55, 45, 48, 50, 54, 56, 50]

df = pd.DataFrame(data)

print(df)

Name DOB Gender Mobile Height Weight

0 ADITYA PAL 01/12/2002 M 9876543210 5.8 55

1 PALAK AGARWAL 08/11/2002 F 9987654321 5.0 45

2 KULDEEP SINGH 12/02/2003 M 9998765432 5.3 48

3 NEHA 02/05/2003 F 9999765432 5.3 50

4 PRAVESH 03/05/2002 M 8885963212 5.5 54

5 SUMIT PACHORI 05/03/2001 M 8956664232 5.6 56

6 TANUSHKA 02/02/2002 F 9856472362 5.1 50

Q2. Write the result of following Statements based on above DataFrame

a. print(df.index)

RangeIndex(start=0, stop=7, step=1)

b. print(df.columns)

Index(['Name', 'DOB', 'Gender', 'Mobile', 'Height', 'Weight'], dtype='object')

c. print(df.ndim)

2
Q3. What the following statements are doing to DataFrame df?

a. df['city'] = ['Gwalior','Indore','Agra','Dewas','Gwalior','Indore']

The above statement will give an error because the given values are only 6 whereas dataframe

have 7 rows.

b. df.Name[7] = ['NANDITA', '2020/01/01', 'F', 9998887776, 5.3, 51]

The above statement will give an error because to add an row it is needed to write "df.loc"

instead of "df.Name".

c. df.loc[2, : ]

The above statement will show all the details of that person who is at 3rd position in the

dataframe.

print(df.loc[2, : ])

Name KULDEEP SINGH

DOB 12/02/2003

Gender M

Mobile 9998765432

Height 5.3

Weight 48

Name: 2, dtype: object

d. df.loc[3:5, : ]

The above statement will show all the details of those person who are at 4th to 6th position

in the dataframe.

print(df.loc[3:5, : ])

Name DOB Gender Mobile Height Weight


3 NEHA 02/05/2003 F 9999765432 5.3 50

4 PRAVESH 03/05/2002 M 8885963212 5.5 54

5 SUMIT PACHORI 05/03/2001 M 8956664232 5.6 56

e. df.loc[2:4, 'Name' : 'Gender']

The above statement will show all the rows of those person who are at 3rd to 5th position in

the dataframe and those columns who are between Name and Gender including these columns.

print(df.loc[2:4, 'Name' : 'Gender'])

Name DOB Gender

2 KULDEEP SINGH 12/02/2003 M

3 NEHA 02/05/2003 F

4 PRAVESH 03/05/2002 M

Q4. Add One more Column 'FName' with suitable contents to the above Data Frame .

df["FName"] = ["Arun Pal", "Rakesh Agarwal", "Pawan Singh", "Mudit", "Karan", "Manish Pachori",
"Shivam"]

print(df)

Name DOB Gender Mobile Height Weight FName

0 ADITYA PAL 01/12/2002 M 9876543210 5.8 55 Arun Pal

1 PALAK AGARWAL 08/11/2002 F 9987654321 5.0 45 Rakesh Agarwal

2 KULDEEP SINGH 12/02/2003 M 9998765432 5.3 48 Pawan Singh

3 NEHA 02/05/2003 F 9999765432 5.3 50 Mudit

4 PRAVESH 03/05/2002 M 8885963212 5.5 54 Karan

5 SUMIT PACHORI 05/03/2001 M 8956664232 5.6 56 Manish Pachori

6 TANUSHKA 02/02/2002 F 9856472362 5.1 50 Shivam

Q5. Identify the Output of the following commands.

(a)print(df.count(0))
Name 7

DOB 7

Gender 7

Mobile 7

Height 7

Weight 7

FName 7

dtype: int64

(b)print(df.count(1))

0 7

1 7

2 7

3 7

4 7

5 7

6 7

dtype: int64

(c)print(df.T)

0 1 2 3 4 5 6

Name ADITYA PAL PALAK AGARWAL KULDEEP SINGH NEHA PRAVESH SUMIT PACHORI
TANUSHKA

DOB 01/12/2002 08/11/2002 12/02/2003 02/05/2003 03/05/2002 05/03/2001


02/02/2002

Gender M F M F M M F

Mobile 9876543210 9987654321 9998765432 9999765432 8885963212 8956664232


9856472362

Height 5.8 5.0 5.3 5.3 5.5 5.6 5.1


Weight 55 45 48 50 54 56 50

FName Arun Pal Rakesh Agarwal Pawan Singh Mudit Karan Manish Pachori Shivam

(d)print(df1.idxmax())

It will show error as dataframe named df1 doesn't exist.

----------------------------------------------------------------------------------------------

Assignment_DataFrame

Q1. If a List L contains the following elements :

L = ['a', 'e', 'i', 'o', 'u']

Write a Python program to create a Series named SL using the above list.

SL = pd.Series(L)

print(SL)

0 a

1 e

2 i

3 o

4 u

dtype: object

Q2. A dictionary D contains the following data :

D = { 'P':16, 'Q':17, 'R':18, 'S':19 }

Write a Python program to create a Series named SD using the above dictionary.

D = { 'P':16, 'Q':17, 'R':18, 'S':19 }

SD = pd.Series(D)
print(SD)

P 16

Q 17

R 18

S 19

dtype: int64

Q3. Explain the usage of head() and tail() function in DataFrame.

head() : It displays the first n members of the DataFrame. If the values for n is not passed,

then by default n takes 5 and the first five members are displayed.

tail() : It displays the last n members of the DataFrame. If the values for n is not passed,

then by default n takes 5 and the last five members are displayed.

Q4. A dictionary called StdX which contains the following data:

+-------------+---------+------------+

| Name | TMarks | City |

+-------------+---------+------------+

| Amit Kumar | 450 | New Delhi |

| Asha Goel | 426 | Bengaluru |

| Kavita | 476 | Chennai |

| Riya | 446 | Jaipur |

| Piyush | 464 | Mumbai |

+-------------+---------+------------+

Based on the above data, answer the following questions.

(Assume that pandas has been imported as pd)

(a) Write a Python statement to create a Data Frame df by using the Dictionary StdX.

StdX = {"Name" : ["Amit Kumar", "Asha Goel", "Kavita", "Riya", "Piyush"],


"TMarks" : [450, 426, 476, 446, 464],

"City" : ["New Delhi", "Benaluru", "Chennai", "Jaipur", "Mumbai"]

df = pd.DataFrame(StdX)

(b) Print the DataFrame df.

print(df)

Name TMarks City

0 Amit Kumar 450 New Delhi

1 Asha Goel 426 Benaluru

2 Kavita 476 Chennai

3 Riya 446 Jaipur

4 Piyush 464 Mumbai

(c) Print the Columns as City, Name, TMarks.

df["City", "Name", "TMarks"]

(d) Print first three rows of the DataFrame df.

print(df.head(3))

Name TMarks City

0 Amit Kumar 450 New Delhi

1 Asha Goel 426 Benaluru

2 Kavita 476 Chennai

(e) Print last two rows of the DataFrame df.

print(df.tail(2))
Name TMarks City

3 Riya 446 Jaipur

4 Piyush 464 Mumbai

(f) Print the total number of records in the DataFrame df.

print(df.count())

Name 5

TMarks 5

City 5

dtype: int64

(g) Add to df , the following 2 rows with the given data:

Ishan, 435, New Delhi

Amrita, 432, Kolkata

data2 = {"Name" : ["Ishan", "Amrita"],

"TMarks" : [435, 432],

"City" : ["New Delhi", "Kolkata"]

df1 = pd.DataFrame(data2)

df = df.append(df1, ignore_index = "True")

(h) Add to df , a new column called Age, with the following data:

[12, 15, 16, 13, 14, 15, 13]

df["Age"] = [12, 15, 16, 13, 14, 15, 13]

(i) Drop the column ‘City’ from df.


df = df.drop("City", axis = 1)

(j) Drop the 3rd row from df.

df = df.drop(3, axis = 0)

(k) Find the output of df.iloc[0:3]

df.iloc[0:3]

Name TMarks City

0 Amit Kumar 450 New Delhi

1 Asha Goel 426 Benaluru

2 Kavita 476 Chennai

Q6. Name the pandas functions/methods that iss used to load a csv file to pandas.

read_csv

----------------------------------------------------------------------------------------------

Matplotlib

Line Plot 1

import matplotlib.pyplot as plt

runs = [20, 12, 18, 5, 14, 3, 13, 9, 16, 25]

overs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

plt.plot(overs, runs)

plt.xlabel("Overs")

plt.ylabel("Runs")
plt.title("Score of an Indian Team")

plt.xticks(overs)

plt.show()

----------------------------------------------------------------------------------------------

Line PLot 2

import matplotlib.pyplot as plt

runs1 = [20, 12, 18, 5, 14, 3, 13, 9, 16, 25]

runs2 = [4, 8, 10, 2, 1, 9, 5, 5, 3, 7]

overs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

plt.plot(overs, runs1, color = "red")

plt.plot(overs, runs2, color = "cyan")

plt.xlabel("Overs")

plt.ylabel("Runs")

plt.title("Score of a Cricket Match")

plt.xticks(overs)

plt.legend(loc["India", "Pakistan"] = "upper left")

plt.show()

----------------------------------------------------------------------------------------------

Line PLot 3

import matplotlib.pyplot as plt

wick1 = [3, 8, 9]

overs1 = [3, 8, 9]

wick2 = [1, 3.2, 3.5, 3.8, 5, 7, 8, 9, 9.5, 10]

overs2 = [1, 3.2, 3.5, 3.8, 5, 7, 8, 9, 9.5, 10]

plt.scatter(overs1, wick1, color = "red", marker = "*")

plt.scatter(overs2, wick2, color = "cyan", marker = "*")

plt.xlabel("Overs")
plt.ylabel("Wickets")

plt.title("Wickets down in Cricket Match")

plt.legend(loc["India", "Pakistan"] = "upper left")

plt.show()

"""

import matplotlib.pyplot as plt

wick1 = [3, 8, 9]

overs1 = [3, 8, 9]

wick2 = [1, 3.2, 3.5, 3.8, 5, 7, 8, 9, 9.5, 10]

overs2 = [1, 3.2, 3.5, 3.8, 5, 7, 8, 9, 9.5, 10]

plt.scatter(overs1, wick1, color = "red", marker = "*")

plt.scatter(overs2, wick2, color = "cyan", marker = "*")

runs1 = [20, 12, 18, 5, 14, 3, 13, 9, 16, 25]

runs2 = [4, 8, 10, 2, 1, 9, 5, 5, 3, 7]

overs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

plt.plot(overs, runs1, color = "red")

plt.plot(overs, runs2, color = "cyan")

plt.xlabel("Overs")

plt.ylabel("Runs")

plt.title("Cricket Match : India VS Pakistan")

plt.legend(loc["India", "Pakistan"] = "upper left")

plt.show()

"""

----------------------------------------------------------------------------------------------

Bar Graph 1

import matplotlib.pyplot as plt

temp = [28, 30, 33, 34, 27, 26, 29]


week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

plt.bar(week, temp)

plt.title("Temperature in a Week.")

plt.xlabel("Weekdays")

plt.ylabel("Temperature")

plt.show()

----------------------------------------------------------------------------------------------

Bar Graph 2

import matplotlib.pyplot as plt

temp = [28, 30, 33, 34, 27, 26, 29]

week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

plt.bar(week, temp, color = "blue", linestyle = "--", linewidth = 1, edgecolor = "magenta")

plt.title("Temperature in a Week.")

plt.xlabel("Weekdays")

plt.ylabel("Temperature")

plt.yticks(temp)

plt.show()

----------------------------------------------------------------------------------------------

Bar Graph 3

import matplotlib.pyplot as plt

temp1 = [28, 30, 33, 34, 27, 26, 29]

temp2 = [30, 33, 36, 34, 32, 30, 30]

temp3 = [28, 29, 27, 25, 22, 24, 26]

week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

plt.bar(week, temp1, color = "blue", linestyle = "--", linewidth = 1, edgecolor = "magenta")


plt.bar(week, temp2, color = "yellow", linestyle = "--", linewidth = 1, edgecolor = "magenta")

plt.bar(week, temp3, color = "green", linestyle = "--", linewidth = 1, edgecolor = "magenta")

plt.title("Temperature in 3 Weeks.")

plt.xlabel("Weekdays")

plt.ylabel("Temperature")

plt.yticks(temp)

plt.legend(loc["Week 1", "Week 2", "Week 3"] = "upper left")

plt.show()

----------------------------------------------------------------------------------------------

Histogram 1

import matplotlib.pyplot as plt

sales = [0, 0, 0, 2000, 5000, 5000, 7500, 8700, 8000, 10000, 12000, 9500]

month = ["January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"]

plt.hist(month, sales)

plt.title("Sales in a year")

plt.xlabel("Months")

plt.ylabel("Sales")

plt.show()

----------------------------------------------------------------------------------------------

Histogram 2

import matplotlib.pyplot as plt

sales = [0, 0, 0, 2000, 5000, 5000, 7500, 8700, 8000, 10000, 12000, 9500]

month = ["January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"]

plt.hist(month, sales, linestyle = ":", linewidth = "2", edgecolor = "green", fill = False, hatch = "o")
plt.title("Sales in a year")

plt.xlabel("Months")

plt.ylabel("Sales")

plt.legend(loc["sales"] = "upper left")

plt.show() DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')


Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price
0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".


df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)
School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.
print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN
A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],
"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]


Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],


["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])


Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }


totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

4
----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price


0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3
Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)
(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)
Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500


Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150


1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2
CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0
Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.


df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200


3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18
CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)
1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.


import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2
CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .


Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]


df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)
Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)
Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".


df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)
School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20
Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN
Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.


import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.
df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],


["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.
print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd
Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())
4

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like


Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------
DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape
(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.


print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180


2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)


Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8
CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0
C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

}
Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135


1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

]
Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper
CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)
print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2
Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150


2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .


Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]
School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1
Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')


Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :


[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225


3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8
Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.


print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)
print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None


Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10
CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2
Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd
data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8
Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.


import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]


Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')


Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price
0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".


df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)
School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.
print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN
A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],
"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]


Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],


["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])


Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }


totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

4
----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price


0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3
Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)
(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)
Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500


Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150


1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2
CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0
Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.


df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200


3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18
CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)
1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.


import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2
CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .


Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]


df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)
Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)
Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".


df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)
School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20
Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN
Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.


import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.
df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],


["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.
print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd
Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())
4

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like


Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------
DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape
(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.


print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180


2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)


Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8
CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0
C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

}
Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135


1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

]
Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper
CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)
print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2
Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150


2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .


Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]
School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1
Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')


Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :


[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225


3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8
Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.


print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)
print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None


Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10
CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2
Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd
data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8
Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.


import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]


Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')


Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price
0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".


df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)
School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.
print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN
A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],
"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]


Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],


["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])


Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }


totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

4
----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price


0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3
Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)
(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)
Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500


Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150


1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2
CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0
Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.


df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200


3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18
CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)
1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.


import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2
CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .


Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]


df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)
Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)
Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".


df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)
School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20
Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN
Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.


import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.
df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],


["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.
print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd
Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())
4

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like


Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------
DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape
(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.


print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180


2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)


Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8
CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0
C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

}
Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135


1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

]
Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper
CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)
print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2
Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150


2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .


Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]
School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1
Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')


Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :


[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225


3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8
Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.


print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)
print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None


Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10
CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2
Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd
data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8
Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.


import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]


Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')


Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price
0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".


df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)
School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.
print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN
A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],
"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]


Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],


["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])


Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }


totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

4
----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price


0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3
Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)
(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)
Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500


Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150


1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2
CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0
Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.


df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200


3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18
CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)
1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.


import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2
CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .


Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]


df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.


import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())
4

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]


Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------
DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape
(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')


Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150


1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)


Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup


CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.
print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0
B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]


}

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price


0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]


]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])


Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}


df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------
DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135


1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .


Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]
School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1
Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)
Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500


Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180


2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8
CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.


print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.


df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10
CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2
Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd
data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8
Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.


import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]


Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')


Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price
0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".


df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)
School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.
print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN
A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],
"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]


Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],


["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])


Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }


totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

4
----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price


0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3
Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)
(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)
Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500


Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150


1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2
CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])
DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0
Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.


df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200


3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.


df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =
["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18
CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .

Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)
1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.

print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .


Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]

df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440


Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800

----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.


import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:

(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2
CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

DataFrame 1

Write suitable python statement for the following .


Q1. Make a DataFrame using the DataFrame given above.

import pandas as pd

Year1 = {"Q1" : 5000, "Q2" : 8000, "Q3" : 12000, "Q4" : 18000 }

Year2 = {"A" : 13000, "B" : 14000, "C" : 12000 }

totSales = {1 : Year1, 2 : Year2}

df = pd.DataFrame(totSales)

print(df)

1 2

Q1 5000.0 NaN

Q2 8000.0 NaN

Q3 12000.0 NaN

Q4 18000.0 NaN

A NaN 13000.0

B NaN 14000.0

C NaN 12000.0

Q2. List the index of the DataFrame df.

print(df.index)

Index(['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'], dtype='object')

Q3. List the colummns of the DataFrame df.

print(df.columns)

Int64Index([1, 2], dtype='int64')

Q4. Count the total number of records in the 1st column.


print(df[1].count())

----------------------------------------------------------------------------------------------

DataFrame 2

Write suitable python statement for the following .

Q1. Make a dictionary of lists using the DataFrame given above.

import pandas as pd

data = {"Name" : ["Nancy Drew", "Hardy Boys", "Diary of a wimpy kid", "Harry Potter"],

"Price" : [150, 180, 225, 500]

Q2. Make a DataFrame using the dictionary of lists given above.

df1 = pd.DataFrame(data)

print(df1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

Q3. Add a column called Special_Price with the following data :

[135, 150, 200, 440]


df1["Special_Price"] = [135, 150, 200, 440]

Updated DataFrame will look like

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

Q4. Add a new book named "The Secret" having price 800.

df1.loc["4"] = ["The Secret", 800, None]

Name Price Special_Price

0 Nancy Drew 150 135

1 Hardy Boys 180 150

2 Diary of a wimpy kid 225 200

3 Harry Potter 500 440

4 The Secret 800 None

Q5. Remove the column "Special_Price".

df1 = df1.drop("Special_Price", axis = 1)

Name Price

0 Nancy Drew 150

1 Hardy Boys 180

2 Diary of a wimpy kid 225

3 Harry Potter 500

4 The Secret 800


----------------------------------------------------------------------------------------------

DataFrame 3

Write suitable python statement for the following .

Q1. Make a list of lists using the DataFrame given above.

import pandas as pd

data = [["PPS", 40, 32, 8],

["JPS", 30, 18, 12],

["GPS", 20, 18, 2],

["MPS", 18, 10, 8],

["BPS", 28, 20, 8]

Q2. Make a DataFrame using the list of lists given above.

df3 = pd.DataFrame(data, columns = ["School", "Tot_students", "Topper", "First_Runnerup"], index =


["CO1", "CO2", "CO3", "CO4", "CO5"])

print(df3)

School Tot_students Topper First_Runnerup

CO1 PPS 40 32 8

CO2 JPS 30 18 12

CO3 GPS 20 18 2

CO4 MPS 18 10 8

CO5 BPS 28 20 8

Q3. Predict the output of the following python statement:


(a) df3.shape

(5, 4)

(b) df3[2:4]

School Tot_students Topper First_Runnerup

CO3 GPS 20 18 2

CO4 MPS 18 10 8

Q4. Write the python statement to display the data of Topper column of indexes CO2 to CO4.

print(df3.loc["CO2" : "CO5", ["Topper"]])

Topper

CO2 18

CO3 18

CO4 10

CO5 20

Q5. Write the python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.

print(df3.loc[df.Tot_students - df.First_Runnerup])

You might also like