Matplotlib: How can i use a column as data segmentation on matplotlib?

264 views Asked by At

i've a question about matplotlib.

I have a table just like this.

data = pd.Dataframe(alldata)

print(data)


index | id |  type   |  date   | value |
---------------------------------------
0   | 1  | apples   | 01-01-15| 100.00|
0   | 1  | apples   | 01-01-16| 100.10|
0   | 1  | apples   | 01-01-17| 100.15|
0   | 2  | bananas  | 01-01-15| 100.00|
0   | 2  | bananas  | 01-01-16| 100.05|
0   | 2  | bananas  | 01-01-17| 100.06|
0   | 3  | grapes   | 01-01-15| 100.00|
0   | 3  | grapes   | 01-01-16| 100.20|
0   | 3  | grapes   | 01-01-17| 100.40|

My intention is to plot a line graph on x = date and y = values, but instead to create just one line.. i want to create 3 lines comparing one with other, using 'type' as a parameter.

I've tried to divide my data, as this:

x = data['data']
y1 = data['value'][data.type == 'apples']
y2 = data['value'][data.type == 'bananas']

and create a plot like..

plt.plot(x,y1)
plt.plot(x,y2)

but it didn't worked.

How can i use data segmentation for a specific parameter like this on matplotlib?

Thx a lot!

0

There are 0 answers