Reputation: 779
I have a dataframe with 2 columns and 50 rows.
A B
1 5 9
2 4 2
3 7 1
...
I want to draw a graph, in which X-axis will be the index, red line will be the value of A at that point, and blue line will be the value of B.
What's the best way to do so?
Upvotes: 0
Views: 106
Reputation: 88236
How about DataFrame.plot()
?
print(df)
A B
1 5 9
2 4 2
3 7 1
df.plot(color=['red','blue'])
Upvotes: 1
Reputation: 3967
Here's an example using matplotlib
:
a = np.arange(50)
np.random.shuffle(a)
b = np.linspace(50, 100, 50)
np.random.shuffle(b)
df = pd.DataFrame({'A':a, 'B':b})
plt.plot(df.index, df.B, label='B')
plt.plot(df.index, df.A, c='r', label='A')
plt.legend()
plt.show()
Upvotes: 0