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

Dataframe.plot error (on version 0.25.1) #28593

Open
ganhw1970 opened this issue Sep 24, 2019 · 0 comments
Open

Dataframe.plot error (on version 0.25.1) #28593

ganhw1970 opened this issue Sep 24, 2019 · 0 comments
Labels

Comments

@ganhw1970
Copy link

Code Sample, a copy-pastable example if possible

# Your code here
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
da = np.arange(12).reshape(6,2)
df=pd.DataFrame(da,columns=list('ab'))
fig, ax = plt.subplots()
df[['a']].plot(x=df['b'],ax=ax)
plt.show()

Problem description

these test code run ok on pandas version 0.20.0 ,but error on pandas version is 0.25.1.
the error info is:
KeyError: "None of [Int64Index([1, 3, 5, 7, 9, 11], dtype='int64')] are in the [columns]"

the detail trace info are:

File "E:/pytest/dfplot1.py", line 7, in
df[['a']].plot(x=df['b'],ax=ax)
File "C:\Program Files\Python37\lib\site-packages\pandas\plotting_core.py", line 759, in call
elif not isinstance(data[x], ABCSeries):
File "C:\Program Files\Python37\lib\site-packages\pandas\core\frame.py", line 2986, in getitem
indexer = self.loc._convert_to_indexer(key, axis=1, raise_missing=True)
File "C:\Program Files\Python37\lib\site-packages\pandas\core\indexing.py", line 1285, in _convert_to_indexer
return self._get_listlike_indexer(obj, axis, **kwargs)[1]
File "C:\Program Files\Python37\lib\site-packages\pandas\core\indexing.py", line 1092, in _get_listlike_indexer
keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
File "C:\Program Files\Python37\lib\site-packages\pandas\core\indexing.py", line 1177, in _validate_read_indexer
key=key, axis=self.obj._get_axis_name(axis)
KeyError: "None of [Int64Index([1, 3, 5, 7, 9, 11], dtype='int64')] are in the [columns]"

[this should explain why the current behaviour is a problem and why the expected output is a better solution.]

Note: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!

Note: Many problems can be resolved by simply upgrading pandas to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check if master addresses this issue, but that is not necessary.

For documentation-related issues, you can check the latest versions of the docs on master here:

https://pandas-docs.github.io/pandas-docs-travis/

If the issue has not been resolved there, go ahead and file it in the issue tracker.

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Windows
OS-release : 7
machine : AMD64
processor : Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 0.25.1
numpy : 1.17.2
pytz : 2019.2
dateutil : 2.8.0
pip : 19.0.3
setuptools : 40.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 0.9.3
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : 1.3.8
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@jbrockmendel jbrockmendel added the Visualization plotting label Oct 16, 2019
@mroeschke mroeschke added the Bug label Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants