I have a dataframe like this:
name color parking_space
0 Terminal 1, 2 Green Lot 40
1 Terminal 4 Blue Lot 81
2 Terminal 5 Yellow Lot 59
3 Terminal 7 Orange Lot 45
4 Terminal 8 Red Lot 31
5 Long-Term Lot 55
This is the data scraped using selenium.I want to change the background colour of the entire row based on the value of parking_space. here is the code that i have tried.But the output of this is the dataframe which is the same old database. code:
terminal_name=driver.find_elements_by_class_name("tp-h-mod")
terminal_color=driver.find_elements_by_class_name("terminals-lot")
terminal_capacity=driver.find_elements_by_class_name("terminal-percentage")
mylist=[]
mylist1=[]
mylist2=[]
list1=[]
for data in terminal_name:
mylist.append(data.text)
for data in terminal_color:
mylist1.append(data.text)
for data in terminal_capacity:
mylist2.append(data.text)
for i in range(6):
text=mylist2[i]
m=text.split('%')[0]
list1.append(m)
df=pd.DataFrame({'name':mylist,'color':mylist1,'parking_space':list1})
def highlight(row):
if int(row.parking_space[:2]) <= 25:
return ['background-color: green']*3
elif int(row.parking_space[:2]) >=26 and int(row.parking_space[:2]) <=50:
return ['background-color:yellow']*3
else:
return ['background-color:red']*3
df.style.apply(highlight, axis=1)
print(df)
path = 'C:/Users/InterCEP/Desktop/parking/'
df.to_html(path+'parking.html')