Worksheet Dataframe
Worksheet 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: