Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More helpful error message when DataFrame.plot fails on some column #478

Closed
mattharrison opened this issue Dec 12, 2011 · 3 comments
Closed
Milestone

Comments

@mattharrison
Copy link

I'm trying to plot a DataFrame and it wasn't working, so I tried loading the data set from the read_csv docs. It also failed. I think I'm missing something, but I've been successful with matplotlib before. :)

from pandas import read_csv
import matplotlib.pyplot as plt

junk = read_csv('bar.csv')
fig = plt.figure()
junk.plot()
fig.savefig('/tmp/foo3.png')

bar.csv

year,indiv,zit,xit
1977,"A",1.2,.6
1977,"B",1.5,.5
1977,"C",1.7,.8
1978,"A",.2,.06
1978,"B",.7,.2
1978,"C",.8,.3
1978,"D",.9,.5
1978,"E",1.4,.9
1979,"C",.2,.15
1979,"D",.14,.05
1979,"E",.5,.15
1979,"F",1.2,.5
1979,"G",3.4,1.9
1979,"H",5.4,2.7
1979,"I",6.4,1.2

I get the folowing error:

python /tmp/plot.py 
Traceback (most recent call last):
  File "/tmp/plot.py", line 6, in <module>
    junk.plot()
  File "/home/mharrison/work/pandas/env/lib/python2.6/site-packages/pandas/core/frame.py", line 3225, in plot
    ax.plot(x, y, label=str(col), **kwds)
  File "/home/mharrison/work/pandas/env/lib/python2.6/site-packages/matplotlib/axes.py", line 3783, in plot
    for line in self._get_lines(*args, **kwargs):
  File "/home/mharrison/work/pandas/env/lib/python2.6/site-packages/matplotlib/axes.py", line 317, in _grab_next_args
    for seg in self._plot_args(remaining, kwargs):
  File "/home/mharrison/work/pandas/env/lib/python2.6/site-packages/matplotlib/axes.py", line 275, in _plot_args
    linestyle, marker, color = _process_plot_format(tup[-1])
  File "/home/mharrison/work/pandas/env/lib/python2.6/site-packages/matplotlib/axes.py", line 93, in _process_plot_format
    if fmt.find('--')>=0:
AttributeError: 'numpy.ndarray' object has no attribute 'find'
@wesm
Copy link
Member

wesm commented Dec 13, 2011

The problem is that the indiv column is non-numeric. I could probably catch the exception and add a more helpful error message

@mattharrison
Copy link
Author

That makes sense. Yes, a better error would be wonderful. I'll try to post some code to plot the above, then close this.

@wesm
Copy link
Member

wesm commented Dec 13, 2011

added a more helpful error message. going to go ahead and close this

@wesm wesm closed this as completed Dec 13, 2011
dan-nadler pushed a commit to dan-nadler/pandas that referenced this issue Sep 23, 2019
* ENH: Add min date function

Add min date function to match max date function

* TST: Add test for min and max dates

Add test for min and max dates

* ENH: Improve error for min/max date

Raise NoDataFoundException rather than TypeError when no result
is returned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants