Skip to main content

Posts

Showing posts with the label Write a Pandas program to change the percentage in a given row by the user.

ads1

6. Write a Pandas program to change the percentage in a given row by the user.

6.  Write a Pandas program to change the percentage in a given row by the user. Solution :-  import pandas as pd import numpy as np exam_data = {'name':['abc','xyz','mno','pqr','ghk'],              'perc':[79.25,25,69.90,np.nan,87],              'qualify':['yes','no','yes','yes','yes']} labels = ['A','B','C','D','E'] df = pd.DataFrame(exam_data, index = labels) print(" Original data frame :- ") print(df) ch = input("Enter the index of row :- ") per = float(input("Enter the percentage Changed :- ")) print("\n Change the percentage in row '+ch+' to ",per) df.loc[ch, 'perc']=per print(df) Output :- 

ads2