Advertisements
Advertisements
प्रश्न
Write the python statement for the following question on the basis of given dataset:
| Name | Degree | Score | |
| 0 | Aparna | MBA | 90.0 |
| 1 | Pankaj | BCA | NaN |
| 2 | Ram | M.Tech | 80.0 |
| 3 | Ramesh | MBA | 98.0 |
| 4 | Naveen | NaN | 97.0 |
| 5 | Krrishnav | BCA | 78.0 |
| 6 | Bhawna | MBA | 89.0 |
- To create the above DataFrame.
- To print the Degree and maximum marks in each stream.
- To fill the NaN with 76.
- To set the index to Name.
- To display the name and degree wise average marks of each student.
- To count the number of students in MBA.
- To print the mode marks BCA.
कोड लेखन
Advertisements
उत्तर
import pandas as pd
data = {
'Name': ['Aparna', 'Pankaj', 'Ram', 'Ramesh', 'Naveen', 'Krrishnav', 'Bhawna'],
'Degree': ['MBA', 'BCA', 'M.Tech', 'MBA', None, 'BCA', 'MBA'],
'Score': [90.0, None, 80.0, 98.0, 97.0, 78.0, 89.0]
}
df = pd.DataFrame(data)
print(df)
b)
print(df.groupby('Degree')['Score'].max())
c)
df.fillna(76, inplace=True)
print(df)
d)
df.set_index('Name', inplace=True)
print(df)
e)
print(df.groupby(['Name', 'Degree'])'Score'].mean())
f)
print((df['Degree'] == 'MBA').sum())
g)
print(df[df['Degree'] == 'BCA']'Score'].mode())
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
