Q:

Use dataframe column names as labels in pylab.plot

I would like to plot the data in a dataframe and have the column headers be the labels.  I tried this:
dfm.columns = ['a','b']
plot(dfm.cumsum(), label= dfm.columns.values)
legend(loc='upper left')

But got this:

Instead of both lines being labeled ['a','b'], I'd like the blue line to be a and the green to be b using pylab

A:

I think it's the way you have your data set up in part of the code you're not showing.
Here's an example, I used df.plot() in this case.
import pandas as pd
import random
import matplotlib.pyplot as plt

x = [random.randint(10,20) for r in range(100)]
y = [random.randint(0,10) for r in range(100)]

df = pd.DataFrame([x,y]).T #T for transpose

df.columns=['a','b']

df.plot(kind='line')

plt.legend(loc='upper left')

plt.show()

Edit
pylab version
import pandas as pd
import random
import matplotlib.pylab as plt

x = [random.randint(10,20) for r in range(100)]
y = [random.randint(0,10) for r in range(100)]

df = pd.DataFrame([x,y]).T

plt.plot(df)

plt.legend(['a','b'],loc='upper left')

plt.show()

