Create Data Table Project

Create Data Table Project

Python Data Problem

 

Given the following sales data (EUR) of 5 shops online during the first half of the year:

  • Sales in January of all shops
    [‘25000’, ‘89500’, ‘63000’, ‘45000’, ‘2600’, ‘120’]
  • Sales in February of all shops
    [‘874000’, ‘895000’, ‘412569’, ‘963258’, ‘741258’, ‘456789’]
  • Sales in March of all shops
    [‘2500’, ‘84500’, ‘68000’, ‘41000’, ‘2900’, ‘160’]
  • Sales in April of all shops
    [‘2890’, ‘840’, ‘680’, ‘410’, ‘290’, ’45’]
  • Sales in May of all shops
    [’12’, ’80’, ’68’, ’42’, ’29’, ’15’]

Write a Python program that displays the data as a table. The columns should be the month of the year, the side rows should be the online shops and the data in the middle the sales figures included in the lists.
The position of the sales amount in the list corresponds to each shop. Therefore the first element in the January sales list corresponds to the sales of the first shop. The second element of the February sales list corresponds to the amount sold by the shop 2 and so on,

The header and side rows must be defined through underscores and pipes. The program must not use the Pandas library.

Expected ouput

python data problem

Solution


# Given data
website = ['shop1', 'shop2', 'shop3', 'shop4', 'shop5']
month = ['jan', 'feb', 'mar', 'apr', 'may', 'jun']
january = ['25000', '89500', '63000', '45000', '2600', '120']
february = ['874000', '895000', '412569', '963258', '741258', '456789']
march = ['2500', '84500', '68000', '41000', '2900', '160']
april = ['2890', '840', '680', '410', '290', '45']
may = ['12', '80', '68', '42', '29', '15']
jun = ['350','2560','13500','890','4356']
# Print the header row
print(f"{'Website':<10} | {'Jan':<10} | {'Feb':<10} | {'Mar':<10} | {'Apr':<10} | {'May':<10} | {'Jun':<10}")

# Print the separator
print('-' * 80)

# Print the data rows
for i in range(len(website)):
    print(f"{website[i]:<10} | {january[i]:<10} | {february[i]:<10} | {march[i]:<10} | {april[i]:<10} | {may[i]:<10} | {jun[i]:<10}")

See here for additional real data projects.

We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for practice
Register New Account
Shopping cart