2

I'm attempting to display a dataframe as a bar graph with a custom date range for xlim. I'm able to output a graph if I select kind='line' but I get the following error message when attempting kind='bar':

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

the dataframe looks as follows:

df1 = 
     Date         Quantity
0    2010-01-01   1  
1    2010-01-02   0
2    2010-01-03   0
3    2010-01-04   2
4    2010-01-05   3
5    2010-01-06   1
6    2010-01-07   0
7    2010-01-08   1
8    2010-01-09   1
9    2010-01-10   2
10   2010-01-11   0
11   2010-01-12   5
12   2010-01-13   2
13   2010-01-14   1
14   2010-01-15   2
...

This works:

df1.plot(x='Date', y='Quantity', kind='line', grid=False, legend=False, 
         xlim=['2010-01-01', '2010-01-10'], figsize=(40, 16))

but this doesn't

    df1.plot(x='Date', y='Quantity', kind='bar', grid=False, legend=False, 
         xlim=['2010-01-01', '2010-01-10'], figsize=(40, 16))

Yet if I remove xlim from kind='bar' I produce an output. It would be nice to be able to output a bar graph with a custom x range.

1 Answer 1

2

What about an alternative approach - filtering your data before plotting?

In [10]: df.set_index('Date').ix['2010-01-01' : '2010-01-10']
Out[10]:
            Quantity
Date
2010-01-01         1
2010-01-02         0
2010-01-03         0
2010-01-04         2
2010-01-05         3
2010-01-06         1
2010-01-07         0
2010-01-08         1
2010-01-09         1
2010-01-10         2

In [11]: df.set_index('Date').ix['2010-01-01' : '2010-01-10', 'Quantity'].plot.bar(grid=False, legend=False)
Sign up to request clarification or add additional context in comments.

2 Comments

The solution works, but I have to drop all other irrelevant columns otherwise they plot. For what I need, this is what I've been looking for.
@Lukasz, you can do it this way: df.set_index('Date').ix['2010-01-01' : '2010-01-10', 'Quantity'].plot... instead of dropping other columns...

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.