研究完数据集中的正确行后,我将结果放入列表中。但是当我打印列表时,python剪切了我的字符串,并且以一种奇怪的方式打印了它。我该如何解决?
import project_fun as fun
#This class is created to manage the university information required to the project
class university:
study="" #Fiel of study desired
budget=0 #Annual budget
info=[] #All the other information about the university
#The init function in this case do not set all the attributes of the class because the info list will be set after the research function
def __init__(self,s,b):
self.study=s
self.budget=b
def __str__(self):
return ("The best university to study "+self.study+", with a budget of "+str(self.budget)+"$ where you can go is: "+self.get_description())
#The function launch all the function created to calculate the best university
def research(self):
csvRank=fun.createdfUni() #Creating university df
corsi=fun.createdfCourses() #Creating course df
possibleUni=fun.findUniversity(corsi,self.study) #Searching all the university with our course of study
#Here we call function to calculate budget with instead the function to find all the information and our budget
myUni=fun.budget(fun.university(csvRank,possibleUni),self.budget)
self.info=myUni #setting self.info attribute
#The function return the description of our university to be used on the __str__ function
def get_description(self):
return str(self.info[0]["Description"])
#Given to the function the courses dataframe and a field of study returns a list with only the names of all the university where you can study
def findUniversity(df,course):
a=df[df["Faculty"] == course]
loc=[]
for i in a.index:
loc.append(a.at[i,"University"])
return loc
#Given to the function the dataset university and the list of names where you can study, return a list with all the information about the university that there are in the list of names
def university(df,listed):
ret=[]
for i in range(len(listed)):
a=df[df["Name"] == listed[i]]
ret.append(a)
return ret
#Given to the function the list of university with all the information, after fixing reading problems and calculate the budget (by total for 12 moth added to the tuition and fees), create a list with only the university that are under the annual budget given
def budget(uni,myBudget):
ret=[]
for x in range(len(uni)):
for i,j in zip(uni[x]["Total"],uni[x]["Tuition and fees"]):
ii=i.replace(',','.') #Fixing reading problem of , instead the .
jj=j.replace('$','') #Removing $ symbol
jjj=jj.replace(',','')
tot=(float(ii)*12)+float(jjj)
if (tot<myBudget):
ret.append(uni[x])
return ret
实际结果: 最好的大学学习商科,您可以去的预算为76000 $是:城市 康涅狄格州耶鲁大学纽黑文分校,位于康涅狄格州纽黑文市... 名称:说明,dtype:对象 我希望“ ...”之后的所有字符串都没有“名称”和“ dtype”