1

I want to make a line graph of the lowest price within three table columns. However the figure keeps returning a whole block instead of a line.enter image description here

DATA TABLE a preview of the data table is given as a screenshot so you'll get an idea of the problem

PLOT [enter image description here](https://i.stack.imgur.com/qxnpL.png)

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']
    ts = readData['timestamp']
    
    # empty dataset
    dataPearls = np.zeros(len(ts))
    dataBananas = np.zeros(len(ts))
    
    i = 0
    for i in range(len(ts)-1):
        if(ts[i+1] < ts[i]):
            print('error')
        else:
            #checks if product is PEARLS
            if(product[i] == 'PEARLS'):
                # als prijs 1 lager is dan 2, i is de prijs van 1
                if(price3[i] < price2[i]):
                    dataPearls[i] = price3[i]
                elif(price2[i] < price1[i]):
                    dataPearls[i] = price2[i]
                elif(price1[i] < price2[i]):
                    dataPearls[i] = price1[i]
                
            '''
            #checks if product is BANANAS
            elif(product[i]=='BANANAS'):
                # here comes code
                print('works')
            else:
                print('error')
            '''
    
    # end of function
    return price1, price2, price3, product, ts, dataPearls, dataBananas

#set variables
price1 = checkPrice()[0]
price2 = checkPrice()[1]
price3 = checkPrice()[2]

dataPearls = checkPrice()[5]
dataBananas = checkPrice()[6]

# 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()
Martijn Z.
  • 19
  • 3

0 Answers0