我想接受用户输入并将其存储到数据帧中。用户输入品牌,型号,类型和评级。然后我想打印用户输入的数据帧表。所以这就是我到目前为止所拥有的
接受用户输入
t = int(input("Enter the number of car instances: "))
ca = cb = cc = cd = ce = cf = 0.0
carList = {'make': [],
'model': [],
'type': [],
'rating': []}
df = pd.DataFrame(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):
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]))