0% found this document useful (0 votes)
307 views5 pages

Worksheet On Pandas Dataframe

The document is a worksheet containing various questions related to creating and manipulating Pandas DataFrames using Python code. It includes tasks such as creating DataFrames from lists and dictionaries, adding and removing columns and rows, and saving DataFrames to CSV files. Each question is assigned a specific mark value, indicating its complexity or importance.

Uploaded by

Lav Gamer India
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
307 views5 pages

Worksheet On Pandas Dataframe

The document is a worksheet containing various questions related to creating and manipulating Pandas DataFrames using Python code. It includes tasks such as creating DataFrames from lists and dictionaries, adding and removing columns and rows, and saving DataFrames to CSV files. Each question is assigned a specific mark value, indicating its complexity or importance.

Uploaded by

Lav Gamer India
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Worksheet on Pandas Dataframe

Date – 27 March 2023

QN Questions M
1 Write a Python code to create a DataFrame stock with appropriate column headings 2
from the list given below:
[[101,'Gurman',98], [102,'Rajveer',95], [103,'Samar' ,96], [104,'Yuvraj',88]]

2 Write a Python code to create a DataFrame ‘Stock’ by using list: 2


Name Price
0 Nancy Drew 150
1 Hardy boys 180
2 Diary of a wimpy kid 225
3 Harry Potter 500
3 Write a Python code to create a DataFrame ‘Stock’ by using dictionary method: 2
Name Price
0 Nancy Drew 150
1 Hardy boys 180
2 Diary of a wimpy kid 225
3 Harry Potter 500

4 Write a Python code to create a DataFrame ‘Stock’ by using Series method: 2


Name Price
0 Nancy Drew 150
1 Hardy boys 180
2 Diary of a wimpy kid 225
3 Harry Potter 500

5 Find output of following code import 2


pandas as pd
Year1={'Q1':[5000,10],'Q2':[8000,20],'Q3':[12000,30],'Q4':[18000,4
0]}
df=pd.DataFrame(Year1) print(df)

6 Find output of following code import 2


pandas as pd
Year1={'Q1':[5000,10],'Q2':[8000,20],'Q3':[12000,30],'Q4':[18000,4
0]}
totSales={1:Year1} df=pd.DataFrame(totSales)
print(df)

7 What will be the output of following code and Answer the following: 2
i. List the index of the DataFrame df
ii. List the column names of DataFrame df.
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)
8 Consider the given DataFrame ‘Stock’: 4
Name Price
0 Nancy Drew 150
1 Hardy boys 180
2 Diary of a wimpy kid 225
3 Harry Potter 500
Write suitable Python statements for the following:
i. Add a column called Special_Price with the following data:
[135,150,200,440].
ii. Add a new book named ‘The Secret' having price 800.
iii. Remove the column Price.
iv.Remove first and third rows from DataFrame
9 Consider the given DataFrame df: 4

Q1 Q2 Q3 Q4
0 5000 8000 12000 18000
1 10 20 30 40
Write suitable Python statements for the following:
i. Add a column called Q5 with the following data: [2000,44].
ii. Add a new record with appropriate values.
iii. Remove the column Q2, Q4. iv.Remove first and second rows from
DataFrame.

10 Write a python code to create empty DataFrame 1


11 Write a Python code to create a DataFrame with appropriate column headings 2
from the csv file given below: city Maxtemp Mintemp Rainfall 0
Delhi 40 32 24.1
1 Bengaluru 31 25 36.2 2 Chennai
35 27 40.8
3 Mumbai 29 21 35.2

12 Write a Python code to create a DataFrame ‘temp’ by using list: 2


city Maxtemp Mintemp Rainfall 0
Delhi 40 32 24.1
1 Bengaluru 31 25 36.2 2 Chennai
35 27 40.8
3 Mumbai 29 21 35.2
13 Write a Python code to create a DataFrame ‘temp’ by using dictionary method: 2
city Maxtemp Mintemp Rainfall 0
Delhi 40 32 24.1
1 Bengaluru 31 25 36.2 2 Chennai
35 27 40.8
3 Mumbai 29 21 35.2

14 Write a Python code to create a DataFrame ‘temp’ by using Series method: 2


city Maxtemp Mintemp Rainfall 0
Delhi 40 32 24.1
1 Bengaluru 31 25 36.2 2 Chennai
35 27 40.8
3 Mumbai 29 21 35.2
15 Find output of following code import pandas as pd 2
x={'Qtr1':[5000,10],'Qtr2':[8000,20],'Qtr3':[12000,30],'Qtr4':[18000,
40]}
df=pd.DataFrame(x) print(df)

16 Find output of following code import pandas as pd 2


x={'Qtr1':[5000,10],'Qtr2':[8000,20],'Qtr3':[12000,30],'Qtr4':[18000,
40]} totSales={1:x}
df=pd.DataFrame(totSales)
print(df)

17 What will be the output of following code and Answer the following: 2
i. List the index of the DataFrame df
ii. List the column names of DataFrame df.
import pandas as pd
x={'Qtr1':5000,'Qtr2':8000,'Qtr3':12000,'Qtr4': 18000} y={'p'
:13000,'q':14000,'r':12000} totSales={1:x,2:y}
df=pd.DataFrame(totSales)
print(df)

18 Consider the given DataFrame ‘temp’: 4


city Maxtemp Mintemp Rainfall 0
Delhi 40 32 24.1
1 Bengaluru 31 25 36.2 2 Chennai
35 27 40.8
3 Mumbai 29 21 35.2
Write suitable Python statements for the following:
i. Add a column called area with the following data:
[135455,153330,225000,442540].
ii. Add a new city named ‘calcutta having maxtemp 20,mintemp 12 and
rainfall
iii. Remove the column rainfall.
iv. iv.Remove first and third rows from DataFrame
19 Consider the given DataFrame df: 4
Qtr1 Qtr2 Qtr3 Qtr4
0 5000 8000 12000 18000
1 10 20 30 40
Write suitable Python statements for the following:
i. Add a column called Qtr5 with the following data: [1444,20].
ii. Add a new record with appropriate values. iii. Remove
the column Qtr1, Qtr3. iv. iv.Remove first and second rows
from DataFrame.

20 Write a python code to create empty DataFrame 1


21 Write a Python code to create a DataFrame ‘lib’ with appropriate column headings 2
from the csv file given below:
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
22 Write a Python code to create a DataFrame ‘lib’ by using list: 2
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
23 Write a Python code to create a DataFrame ‘lib’ by using dictionary method: 2
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70

24 Write a Python code to create a DataFrame ‘lib’ by using Series method: 2


Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
25 Write a Python code to display output of Transpose of DataFrame . 2
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
26 Write a Python code to create a DataFrame ‘lib’ with appropriate column headings 2
save the DataFrame in sample.csv:
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
27 Write a Python code to create a DataFrame ‘temp’ and save the 2
DataFrame in temp.csv file
city Maxtemp Mintemp Rainfall 0
Delhi 40 32 24.1
1 Bengaluru 31 25 36.2 2
Chennai 35 27 40.8
3 Mumbai 29 21 35.2
28 Consider the given DataFrame: 4
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
Write suitable Python statements for the following:
i. Add a column called ACC_NO with the following data:
[135,153,225,442].
ii. Add a new Record
iii. Remove the column qty.
iv. Remove first and third rows from DataFrame
29 Consider the given DataFrame df: 4
A B C D
0 50 80 120 180
1 110 120 130 140
Write suitable Python statements for the following:
i. Add a column called E with the following data: [14,220].
ii. Add a new record with appropriate values. iii. Remove
the column A, C. iv. Remove first and second rows from DataFrame.

30 Consider the given DataFrame df: 1


A B C D
0 50 80 120 180
1 110 120 130 140
Write python code to Transpose df

You might also like