0% found this document useful (0 votes)
0 views2 pages

Worksheet Dataframe

This document contains a worksheet for Class XII focused on creating and manipulating dataframes using Python's pandas library. It includes tasks such as creating dataframes from lists, calculating mean, sum, and median values, and performing operations like addition, subtraction, and renaming columns. Additionally, it addresses common errors in Python syntax related to dataframe creation.

Uploaded by

operagax
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)
0 views2 pages

Worksheet Dataframe

This document contains a worksheet for Class XII focused on creating and manipulating dataframes using Python's pandas library. It includes tasks such as creating dataframes from lists, calculating mean, sum, and median values, and performing operations like addition, subtraction, and renaming columns. Additionally, it addresses common errors in Python syntax related to dataframe creation.

Uploaded by

operagax
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/ 2

WORKSHEET – 1 (DATAFRAME)

CLASS : XII
1. Write a python code to create a dataframe with appropriate headings from the list given
below :
['S101', 'Amy', 70], ['S102', 'Bandhi', 69], ['S104', 'Cathy', 75], ['S105', 'Gundaho', 82]
2. Write a small python code to create a dataframe with headings(a and b) from the list given
below : [[1,2],[3,4],[5,6],[7,8]]
3.Consider the following dataframe, and answer the questions given below:
import pandas as pd
df = pd.DataFrame({“Quarter1":[2000, 4000, 5000, 4400, 10000], "Quarter2":[5800, 2500,
5400, 3000, 2900], "Quarter3":[20000, 16000, 7000, 3600, 8200],
"Quarter4":[1400, 3700, 1700, 2000, 6000]})
(i) Write the code to find mean value from above dataframe df over the index and column
axis.
(ii) Use sum() function to find the sum of all the values over the index axis.
(iii) Find the median of the dataframe df.
4. Given a data frame df1 as shown below:

(i) Write command to compute sum of every column of the data frame.
(ii) Write command to compute mean of column Rainfall.
(iii) Write command to compute Median of the Maxtemp Column.
5. Find the output of the following code:
import pandas as pd
data = [{'a': 10, 'b': 20},{'a': 6, 'b': 32, 'c': 22}]
#with two column indices, values same as dictionary keys
df1 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b'])
#With two column indices with one index with other name
df2 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b1'])
print(df1)
print(df2)
6. Write the code in pandas to create the following dataframes :

Write the commands to do the following operations on the dataframes given above :
(i) To add dataframes df1 and df2.
(ii) To substract df2 from df1
(iii) To rename column mark1 as marks1 in both the dataframes df1 and df2.
(iv) To change index label of df1 from 0 to zero and 1 to one.
7. Consider the following DataFrame, classframe

Write commands to :
i. Add a new column ‘Activity’ to the Dataframe
ii. Add a new row with values ( 5 , Mridula ,X, F , 9.8, Science)
8. Write a program in Python Pandas to create the following DataFrame batsman
from a Dictionary:

Perform the following operations on the DataFrame :


1)Add both the scores of a batsman and assign to column “Total”
2)Display the highest score in both Score1 and Score2 of the DataFrame.
3)Display the DataFrame
9. Mr. Som, a data analyst has designed the DataFrame df that contains data about Computer
Olympiad with ‘CO1’, ‘CO2’, ‘CO3’, ‘CO4’, ‘CO5’ as indexes shown below. Answer the
following questions:

A. Predict the output of the following python statement:


i. df.shape ii.df[2:4]
B. Write Python statement to display the data of Topper column of indexes CO2 to CO4.
C. Write Python statement to compute and display the difference of data of Tot_students
column and First_Runnerup column of the above given DataFrame.
10. The python code written below has syntactical errors. Rewrite the correct code and
underline the corrections made.
Import pandas as pd
df ={"Technology":["Programming","Robotics","3D
Printing"],"Time(in months)":[4,4,3]}
df= Pd.dataframe(df)
Print(df)

You might also like