0

I want to show some data using plots. My dataframe has 3 columns,

Id  Round Time
1   1     158
1   2     169
1   3     172
2   1     156
2   2     168
2   3     176

With this example what I want to do is show 2 lines in my plot (with different colors), each line must correspond to the id, the x axis with the number of the round and the y axis with time.

Now I'm doing this and it's obviously wrong,

import pandas as pd

data = [[1,1,158],[1,2,169],[1,3,172],
        [2,1,156],[2,2,168],[2,3,176]]
cols = ['Id','Round','Time']
df = pd.DataFrame(data, columns=cols)

df.plot(kind='line',x='Round',y='Time')
plt.show()

How can I differentiate each of the different ids?

Thank you very much!!

1 Answer 1

2

You need to create a pivot and then plot it.

In [49]: df.pivot('Round','Id','Time').plot(kind='line')
Out[49]: <matplotlib.axes._subplots.AxesSubplot at 0x2362f31ae10>

In [50]: plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.