English

Write the python statement for the following question on the basis of given dataset: a) To create the above DataFrame. b) To print the Degree and maximum marks in each stream.

Advertisements
Advertisements

Question

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
  1. To create the above DataFrame.
  2. To print the Degree and maximum marks in each stream.
  3. To fill the NaN with 76.
  4. To set the index to Name.
  5. To display the name and degree wise average marks of each student.
  6. To count the number of students in MBA.
  7. To print the mode marks BCA.
Code Writing
Advertisements

Solution

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
  Is there an error in this question or solution?
Chapter 3: Data Handling using Pandas - II - Exercise [Page 103]

APPEARS IN

NCERT Informatics Practices [English] Class 12
Chapter 3 Data Handling using Pandas - II
Exercise | Q 14. | Page 103
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×