Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this code that does the job but not as my assignment has intended. What i

ID: 3790648 • Letter: I

Question

I have this code that does the job but not as my assignment has intended. What i need this do is the exact same thing but with the use of

from pandas import Series, Data Frame

import pandas as pd

import numpy as np

And i'm not sure how to incorporate this into this existing code. Also the output seems a bit messy I'm not sure how to format it and maybe the panda will help with that to align everything uniformly.

Thanks

CODE

class Car(object):

def __init__(self, make=None, model=None, type=None, rating=None):

self.make = make

self.model = model

self.type = type

self.rating = rating

'n/'

print ""

print "NAME: "

print ""

#Coverts a number or string to an interger

t=input("Enter the number of car instances: ")

'n/'

ca=cb=cc=cd=ce=cf=0.0

carList = []

ca_sedan=ca_coupe=ca_suv=0.0

cb_sedan=cb_coupe=cb_suv=0.0

cc_sedan=cc_coupe=cc_suv=0.0

cd_sedan=cd_coupe=cd_suv=0.0

ce_sedan=ce_coupe=ce_suv=0.0

cf_sedan=cf_coupe=cf_suv=0.0

for _ in range(t):

#Returns a list of result of applyg the function to the items of the argument sequence

#splits array into multiple sub-arryays of equal or near equal value

k=map(str,raw_input("Enter the make,model,type,rating: ").split(','))

if(k[3]=='A'):

ca+=1

if k[2]=='sedan': ca_sedan+=1

if k[2]=='coupe': ca_coupe+=1

if k[2]=='SUV': ca_suv+=1

if(k[3]=='B'):

cb+=1

if k[2]=='sedan': cb_sedan+=1

if k[2]=='coupe': cb_coupe+=1

if k[2]=='SUV': cb_suv+=1

if(k[3]=='C'):

cc+=1

if k[2]=='sedan': cc_sedan+=1

if k[2]=='coupe': cc_coupe+=1

if k[2]=='SUV': cc_suv+=1

if(k[3]=='D'):

cd+=1

if k[2]=='sedan': cd_sedan+=1

if k[2]=='coupe': cd_coupe+=1

if k[2]=='SUV': cd_suv+=1

if(k[3]=='E'):

ce+=1

if k[2]=='sedan': ce_sedan+=1

if k[2]=='coupe': ce_coupe+=1

if k[2]=='SUV': ce_suv+=1

if(k[3]=='F'):

cf+=1

if k[2]=='sedan': cf_sedan+=1

if k[2]=='coupe': cf_coupe+=1

if k[2]=='SUV': cf_suv+=1

carList.append(Car(k[0],k[1],k[2],k[3]))

print " make model type rating"

for i in range(t):

print i," ",carList[i].make," ",carList[i].model," ",carList[i].type," ", carList[i].rating

print

print "Prob(rating=A) = '%.6f'" %(ca/t)

print "Prob(rating=B) = '%.6f'" %(cb/t)

print "Prob(rating=C) = '%.6f'" %(cc/t)

print

if ca>0:

print "Prob(type=coupe|rating=A) = '%.6f'" %(ca_coupe/ca)

print "Prob(type=sedan|rating=A) = '%.6f'" %(ca_sedan/ca)

print "Prob(type=SUV|rating=A) = '%.6f'" %(ca_suv/ca)

if cb>0:

print "Prob(type=coupe|rating=B) = '%.6f'" %(cb_coupe/cb)

print "Prob(type=sedan|rating=B) = '%.6f'" %(cb_sedan/cb)

print "Prob(type=SUV|rating=B) = '%.6f'" %(cb_suv/cb)

if cc>0:

print "Prob(type=coupe|rating=C) = '%.6f'" %(cc_coupe/cc)

print "Prob(type=sedan|rating=C) = '%.6f'" %(cc_sedan/cc)

print "Prob(type=SUV|rating=C) = '%.6f'" %(cc_suv/cc)

if cd>0:

print "Prob(type=coupe|rating=D) = '%.6f'" %(cd_coupe/cd)

print "Prob(type=sedan|rating=D) = '%.6f'" %(cd_sedan/cd)

print "Prob(type=SUV|rating=D) = '%.6f'" %(cd_suv/cd)

if ce>0:

print "Prob(type=coupe|rating=E) = '%.6f'" %(ce_coupe/ce)

print "Prob(type=sedan|rating=E) = '%.6f'" %(ce_sedan/ce)

print "Prob(type=SUV|rating=E) = '%.6f'" %(ce_suv/ce)

if cf>0:

print "Prob(type=coupe|rating=F) = '%.6f'" %(cf_coupe/cf)

print "Prob(type=sedan|rating=F) = '%.6f'" %(cf_sedan/cf)

print "Prob(type=SUV|rating=F) = '%.6f'" %(cf_suv/cf)

Explanation / Answer

class Car(object):

def __init__(self, make = None, model = None, type = None, rating = None):
self.make = make
self.model = model
self.type = type
self.rating = rating
print ("")
print ("NAME: ")
print (" ")


#Coverts a number or string to an interger
t = input("Enter the number of car instances: ")
t = int(t)
ca = cb = cc = cd = ce = cf = 0.0
carList = []
ca_sedan = ca_coupe = ca_suv = 0.0
cb_sedan = cb_coupe = cb_suv = 0.0
cc_sedan = cc_coupe = cc_suv = 0.0
cd_sedan = cd_coupe = cd_suv = 0.0
ce_sedan = ce_coupe = ce_suv = 0.0
cf_sedan = cf_coupe = cf_suv = 0.0
for _ in range(t): #Returns a list of result of applyg the function to the items of the argument sequence# splits array into multiple sub - arryays of equal or near equal value
k = map(str, input("Enter the make,model,type,rating: ").split(','))
if (k[3] == 'A'):
ca += 1
if k[2] == 'sedan':
ca_sedan += 1
if k[2] == 'coupe':
ca_coupe += 1
if k[2] == 'SUV':
ca_suv += 1
if (k[3] == 'B'):
cb += 1
if k[2] == 'sedan':
cb_sedan += 1
if k[2] == 'coupe':
cb_coupe += 1
if k[2] == 'SUV': cb_suv += 1
if (k[3] == 'C'):
cc += 1
if k[2] == 'sedan': cc_sedan += 1
if k[2] == 'coupe': cc_coupe += 1
if k[2] == 'SUV': cc_suv += 1
if (k[3] == 'D'):
cd += 1
if k[2] == 'sedan': cd_sedan += 1
if k[2] == 'coupe': cd_coupe += 1
if k[2] == 'SUV': cd_suv += 1
if (k[3] == 'E'):
ce += 1
if k[2] == 'sedan': ce_sedan += 1
if k[2] == 'coupe': ce_coupe += 1
if k[2] == 'SUV': ce_suv += 1
if (k[3] == 'F'):
cf += 1
if k[2] == 'sedan': cf_sedan += 1
if k[2] == 'coupe': cf_coupe += 1
if k[2] == 'SUV': cf_suv += 1
carList.append(Car(k[0], k[1], k[2], k[3]))

print (" make model type rating")
for i in range(t):
print (i, " ", carList[i].make, " ", carList[i].model, " ", carList[i].type, " ", carList[i].rating)
#print
print ("Prob(rating=A) = '%.6f'" % (ca / t))
print ("Prob(rating=B) = '%.6f'" % (cb / t))
print ("Prob(rating=C) = '%.6f'" % (cc / t))

#print
if ca > 0:
print ("Prob(type=coupe|rating=A) = '%.6f'" % (ca_coupe / ca))
print ("Prob(type=sedan|rating=A) = '%.6f'" % (ca_sedan / ca))
print ("Prob(type=SUV|rating=A) = '%.6f'" % (ca_suv / ca))
if cb > 0:
print ("Prob(type=coupe|rating=B) = '%.6f'" % (cb_coupe / cb))
print ("Prob(type=sedan|rating=B) = '%.6f'" % (cb_sedan / cb))
print ("Prob(type=SUV|rating=B) = '%.6f'" % (cb_suv / cb))
if cc > 0:
print ("Prob(type=coupe|rating=C) = '%.6f'" % (cc_coupe / cc))
print ("Prob(type=sedan|rating=C) = '%.6f'" % (cc_sedan / cc))
print ("Prob(type=SUV|rating=C) = '%.6f'" % (cc_suv / cc))
if cd > 0:
print ("Prob(type=coupe|rating=D) = '%.6f'" % (cd_coupe / cd))
print ("Prob(type=sedan|rating=D) = '%.6f'" % (cd_sedan / cd))
print ("Prob(type=SUV|rating=D) = '%.6f'" % (cd_suv / cd))
if ce > 0:
print ("Prob(type=coupe|rating=E) = '%.6f'" % (ce_coupe / ce))
print ("Prob(type=sedan|rating=E) = '%.6f'" % (ce_sedan / ce))
print ("Prob(type=SUV|rating=E) = '%.6f'" % (ce_suv / ce))
if cf > 0:
print ("Prob(type=coupe|rating=F) = '%.6f'" % (cf_coupe / cf))
print ("Prob(type=sedan|rating=F) = '%.6f'" % (cf_sedan / cf))
print ("Prob(type=SUV|rating=F) = '%.6f'" % (cf_suv / cf))

Please provide make ,model,type and rating you are using for testing..Above program compile fine.Please check with your input.