-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Plotting Timedelta on y-axis #16953
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
Comments
I wonder if we could change pandas/pandas/plotting/_core.py Line 343 in 3955261
timedelta=True ? Maybe try changing that and seeing what breaks.
|
After changing
to
it's still raising same exception |
The
|
Plotting import pandas as pd
from pandas.compat import StringIO
import matplotlib.pyplot as plt
dat = """c1,c2,c3
1000,2000,1500
9000,8000,1600"""
df = pd.read_csv(StringIO(dat))
print(df)
print(df.dtypes)
# df.plot.bar()
# plt.show()
df = df.apply(lambda x: pd.to_timedelta(x, unit='ms'))
for col in df.columns:
df[col] = df[col] + pd.to_datetime('1970/01/01')
print(df)
print(df.dtypes)
df.plot.bar()
plt.show() see $ python mwe_pandas.py
c1 c2 c3
0 1000 2000 1500
1 9000 8000 1600
c1 int64
c2 int64
c3 int64
dtype: object
c1 c2 c3
0 1970-01-01 00:00:01 1970-01-01 00:00:02 1970-01-01 00:00:01.500
1 1970-01-01 00:00:09 1970-01-01 00:00:08 1970-01-01 00:00:01.600
c1 datetime64[ns]
c2 datetime64[ns]
c3 datetime64[ns]
dtype: object
Traceback (most recent call last):
File "mwe_pandas.py", line 27, in <module>
df.plot.bar()
File "/Users/scls/anaconda/lib/python3.6/site-packages/pandas/plotting/_core.py", line 2659, in bar
return self(kind='bar', x=x, y=y, **kwds)
File "/Users/scls/anaconda/lib/python3.6/site-packages/pandas/plotting/_core.py", line 2620, in __call__
sort_columns=sort_columns, **kwds)
File "/Users/scls/anaconda/lib/python3.6/site-packages/pandas/plotting/_core.py", line 1857, in plot_frame
**kwds)
File "/Users/scls/anaconda/lib/python3.6/site-packages/pandas/plotting/_core.py", line 1682, in _plot
plot_obj.generate()
File "/Users/scls/anaconda/lib/python3.6/site-packages/pandas/plotting/_core.py", line 236, in generate
self._compute_plot_data()
File "/Users/scls/anaconda/lib/python3.6/site-packages/pandas/plotting/_core.py", line 345, in _compute_plot_data
'plot'.format(numeric_data.__class__.__name__))
TypeError: Empty 'DataFrame': no numeric data to plot |
* implemented fix for GH issue #16953 * added tests for fix of issue #16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
Thanks @s-weigand |
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
Code Sample
Problem description
plot.bar()
works with numerical values (int
,float
).not with
Timedelta
Expected Output
Timedelta on y axis should be displayed
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Darwin
OS-release: 16.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: fr_FR.UTF-8
pandas: 0.20.1
pytest: 3.1.2
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: 0.9.5
IPython: 5.3.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.3
bs4: 4.6.0
html5lib: 0.999
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: 0.4.0
The text was updated successfully, but these errors were encountered: