0

So my objective is to make a visualistation of the best prices on the marktet. The market exists of timestamps with the value of 100 while it counts up to 100000. Every time stamp also has two products. So you'll need to split those best prices up into two different arrays. When I print the array it return the right values for the product 'PEARLS' but it doesn't plot the correct corresponding figure. Does someone know what I need to change in my code?

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import math
from datetime import date
from decimal import *
import csv

# read data file
readData = pd.read_csv('prices_round_1_day_0.csv', delimiter=';', usecols=['day', 'timestamp', 'product', 'bid_price_1', 'bid_price_2', 'bid_price_3'])

''' 
The Program takes the right colums, and prints them out as the way we want it to be
'''

ts = readData['timestamp']

# ts = timestamp
def checkPrice():
    price1 = readData['bid_price_1']
    price2 = readData['bid_price_2']
    price3 = readData['bid_price_3']
    product = readData['product']
    
    # empty dataset
    dataPearls = np.zeros(len(ts))
    dataBananas = np.zeros(len(ts))
    
    for i in range(len(ts)-1):
        if(ts[i+1] < ts[i]):
            # removes error: timestamps incorrect
            print('error, incorrect order of time')
        else:
            # checken wat de hoogste prijs is
            # kijken wat het product is
            # toevoegen aan lege lijst, zodat alle hoogste prijzen erin staan
            
            if (price1[i] >= price2[i] and price1[i] != 0):
                if(product[i] == "PEARLS"):
                    dataPearls[i] = price1[i]
                    i+=1
                # hier moet dezelfde loop in voor de bananen
                else:
                    dataBananas[i] = price1[i]
                    i+=1
            elif (price2[i] >= price3[i] and price2[i] != 0):
                if(product[i] == "PEARLS"):
                    dataPearls[i] = price2[i]
                    i+=1
                else:
                    dataBananas[i] = price2[i]
                    i+=1
            else:
                if(product[i] == "PEARLS" and price3[i] != 0):
                    dataPearls[i] = price3[i]
                    i+=1
                else:
                    dataBananas[i] = price3[i]
                    i+=1


    # end of function
    return dataPearls, dataBananas, price1, price2, price3

print(checkPrice()[0])
print(len(checkPrice()[0]))

#set variables
price1 = checkPrice()[2]
price2 = checkPrice()[3]
price3 = checkPrice()[4]
dataPearls = checkPrice()[0]
dataBananas = checkPrice()[1]

# set axis titles
plt.xlabel('timestamps')
plt.ylabel('prijs')

# plot in grafiek
ax = plt.plot(ts, dataPearls, label="laagste prijs Pearls")
plt.legend()

# run code
checkPrice()

So this is the code I wrote. To give you a better understanding of my problem I have two screen shots. One of the excel sheet and one of the figure plot.[![excel file]figure plot(https://i.stack.imgur.com/QswH4.png)](https://i.stack.imgur.com/QswH4.png)

Martijn Z.
  • 19
  • 3

0 Answers0