CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

1. Consider DataFrame df as shown below :

2.  name age weight height runsscored 0 mayur 15 51 5.1 55 1 anil 16 48 5.2 25 2 viraj 17 49 5.1 71 3 viraj 17 51 5.3 53 4 mahesh 16 48 5.1 51 5 viraj 17 59 5.3 50
• Write command to calculate minimum value for each of the row from subset of dataframe that contains age, weight, height, runsscored
• Write command to calculate mean for last 3 rows.

3. Consider the DataFrame df from above question and write the command for the following:

• Find the name of player with minimum age
• Add a new column BMI to df with value of BMI calculated as (BMI = weigth/height2).

4. Consider the DataFrame:
```dfd = pd.DataFrame({'Name':['Saourabh','Ram','Shyam'],'Percentage':[80,85,82]})
Write the commands for (The output should display a single value):
i) Count the number of Names in dfd
ii) Find the minimum percentage Marks ```

5. What is use of reindex_like() function explain with example and Output.

6. What will be the output of the following python code:
```import pandas as pd
import numpy as np
d = {'Student':['Ali','Ali','Tom','Tom'],\
'House':['Red',Red,'Blue',Blue’],\
'Points':[50,70,60,80]}
df =pd.DataFrame(d)
df1 = df.pivot_table(index='Student',columns='House',values=’Points’,aggfunc=np.sum)
print(df1)
```
7. Write a python statement to fill in the blanks so that the given output of is achieved:
```import pandas as pd
import numpy as np
d = {'Rollno':[101,102,103,104],
'ECO':[70,80,50,80],'BST':[60,50,60,90]}
df = pd.DataFrame(d)
df1 = ___________________________
print(df1)

Output:
Rollno         410
ECO            280
BST            260
dtype:    int64
```

8. 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]
9. How does dataframe specify indexes to its data rows?
10. if a datframe has following values the what will be the output of different statements:
Max speed shield
Viper 1 2
cobra 4 5
Sidevinder 7 8
• df.loc['viper']
• df.loc['cobra':'viper', 'max_speed']