oren_isp
oren_isp

Reputation: 779

python dataframe draw graph of value per row

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

Answers (2)

yatu
yatu

Reputation: 88236

How about DataFrame.plot()?

print(df)
  A  B
1  5  9
2  4  2
3  7  1

df.plot(color=['red','blue'])

enter image description here

Upvotes: 1

meW
meW

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()

enter image description here

Upvotes: 0

Related Questions