I have been trying for the past two days to sort this out and i can't figure it out.
I have a list of dictionaries that needs to be printed out as a table, the employees need to be ranked by the number of properties sold, highest to lowest.
import tabulate
data_list = [
{
'Name': 'John Employee',
'Employee ID': 12345,
'Properties Sold': 5,
'Commission': 2500,
'Bonus to Commission': 0,
'Total Commission': 2500
},
{
'Name': 'Allie Employee',
'Employee ID': 54321,
'Properties Sold': 3,
'Commission': 1500,
'Bonus to Commission': 0,
'Total Commission': 1500
},
{
'Name': 'James Employee',
'Employee ID': 23154,
'Properties Sold': 7,
'Commission': 3500,
'Bonus to Commission': 525,
'Total Commission': 4025
}
]
header = data_list[0].keys()
rows = [x.values() for x in data_list]
print(tabulate.tabulate(rows, header))
Output:
Name Employee ID Properties Sold Commission Bonus to Commission Total Commission
-------------- ------------- ----------------- ------------ --------------------- ------------------
John Employee 12345 5 2500 0 2500
Allie Employee 54321 3 1500 0 1500
James Employee 23154 7 3500 525 4025
Output needed:
Name Employee ID Properties Sold Commission Bonus to Commission Total Commission
-------------- ------------- ----------------- ------------ --------------------- ------------------
James Employee 23154 7 3500 525 4025
John Employee 12345 5 2500 0 2500
Allie Employee 54321 3 1500 0 1500