0

I read data into pandas object and then I want to create a box plot using matplotlib (not pandas.boxplot()). This is just for learning purposes. This is my code, in which myData['MyColumn'] fails.

import matplotlib.pyplot as plt
import pandas as pd

myData = pd.read_csv('data/myData.csv')

plt.boxplot(myData['MyColumn'])

plt.show()
4
  • For your example with one column, just convert the pandas series myData['MyColumn'] into a list Commented Sep 4, 2015 at 19:30
  • @joaquin: How can I do this? Could you give an example? Commented Sep 4, 2015 at 20:03
  • 2
    What's the error you're getting? That worked just fine (on my data) for me. As for the suggestion from @joaquin, I believe he means trying this: plt.boxplot(myData['MyColumn'].values) Commented Sep 4, 2015 at 21:48
  • @Zaphod: Thanks, this solved the problem. Commented Sep 5, 2015 at 8:02

1 Answer 1

1

Your code works fine with fake data. Check the type of the data you're trying to plot.

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
myData = pd.DataFrame(np.random.rand(10, 2), columns=['MyColumn', 'blah'])
plt.boxplot(myData['MyColumn'])
plt.show()
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.