Error when making bar chart from pandas dataframe

Hello,

I can make a bar chart from a pandas groupby object using the pandas .plot() method, which calls matplotlib.
The Bokeh docs say that the bar chart function will take a pandas dataframe, but when i turn that same groupby object into a dataframe, using pandas DataFrame() to give me a dataframe with one index and one data columns,
I get an error. TypeError: cannot concatenate ‘str’ and ‘numpy.int64’ objects
I have included the Ipython Notebook I am working on. I can’t upload the data file it gets data from, but just looking at it without running it should be enough to see the problem. I first do a matplotlib bar chart and then try to do one with Bokeh. Any thoughts on what I am doing wrong would be appreciated.

Chris

Pledges charts bokeh.ipynb (1.46 MB)

Hi Chris,

Unfortunately it is hard to explore without the data. Are you, at least, able to post a csv of CountByDay?

you can get this by doing CountByDay.to_csv(‘filename’)

Sincerely,

Sarah Bird

···

On Mon, Apr 20, 2015 at 11:24 PM, Chris Stehlik [email protected] wrote:

Hello,

I can make a bar chart from a pandas groupby object using the pandas .plot() method, which calls matplotlib.
The Bokeh docs say that the bar chart function will take a pandas dataframe, but when i turn that same groupby object into a dataframe, using pandas DataFrame() to give me a dataframe with one index and one data columns,
I get an error. TypeError: cannot concatenate ‘str’ and ‘numpy.int64’ objects
I have included the Ipython Notebook I am working on. I can’t upload the data file it gets data from, but just looking at it without running it should be enough to see the problem. I first do a matplotlib bar chart and then try to do one with Bokeh. Any thoughts on what I am doing wrong would be appreciated.

Chris

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/900b63b4-2a1f-43b5-a1d8-3f0e034d150a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Sarah,

Yes, I have done that. The entire file has individual donor info and I didn’t want to post that.

Thanks,

Chris

CountByDay.csv (305 Bytes)

···

On Tuesday, April 21, 2015 at 8:31:02 PM UTC-7, Sarah Bird wrote:

Hi Chris,

Unfortunately it is hard to explore without the data. Are you, at least, able to post a csv of CountByDay?

you can get this by doing CountByDay.to_csv(‘filename’)

Sincerely,

Sarah Bird

On Mon, Apr 20, 2015 at 11:24 PM, Chris Stehlik [email protected] wrote:

Hello,

I can make a bar chart from a pandas groupby object using the pandas .plot() method, which calls matplotlib.
The Bokeh docs say that the bar chart function will take a pandas dataframe, but when i turn that same groupby object into a dataframe, using pandas DataFrame() to give me a dataframe with one index and one data columns,
I get an error. TypeError: cannot concatenate ‘str’ and ‘numpy.int64’ objects
I have included the Ipython Notebook I am working on. I can’t upload the data file it gets data from, but just looking at it without running it should be enough to see the problem. I first do a matplotlib bar chart and then try to do one with Bokeh. Any thoughts on what I am doing wrong would be appreciated.

Chris

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/900b63b4-2a1f-43b5-a1d8-3f0e034d150a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Ok,

So quick experimentation shows that when I save CountByDay to csv and then read it back, Bokeh makes a bar chart just fine.
This suggests that the issue is the type of variable of the number data that is the problem. What is Bokeh looking for? Strings? some kind of Numpy num ? (I only know the bare basic of Numpy right now)

···

On Thu, Apr 23, 2015 at 3:19 PM, Chris Stehlik [email protected] wrote:

Hi Sarah,

Yes, I have done that. The entire file has individual donor info and I didn’t want to post that.

Thanks,

Chris

On Tuesday, April 21, 2015 at 8:31:02 PM UTC-7, Sarah Bird wrote:

Hi Chris,

Unfortunately it is hard to explore without the data. Are you, at least, able to post a csv of CountByDay?

you can get this by doing CountByDay.to_csv(‘filename’)

Sincerely,

Sarah Bird

On Mon, Apr 20, 2015 at 11:24 PM, Chris Stehlik [email protected] wrote:

Hello,

I can make a bar chart from a pandas groupby object using the pandas .plot() method, which calls matplotlib.
The Bokeh docs say that the bar chart function will take a pandas dataframe, but when i turn that same groupby object into a dataframe, using pandas DataFrame() to give me a dataframe with one index and one data columns,
I get an error. TypeError: cannot concatenate ‘str’ and ‘numpy.int64’ objects
I have included the Ipython Notebook I am working on. I can’t upload the data file it gets data from, but just looking at it without running it should be enough to see the problem. I first do a matplotlib bar chart and then try to do one with Bokeh. Any thoughts on what I am doing wrong would be appreciated.

Chris

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/900b63b4-2a1f-43b5-a1d8-3f0e034d150a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/AslswU4uPkA/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e9665068-3ecd-4338-820d-a5ba77024182%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Chris,

This should be a bug. I’ve opened an issue here.

Thanks

Fabio

···

On Friday, April 24, 2015 at 12:44:31 AM UTC+2, Chris Stehlik wrote:

Ok,

So quick experimentation shows that when I save CountByDay to csv and then read it back, Bokeh makes a bar chart just fine.
This suggests that the issue is the type of variable of the number data that is the problem. What is Bokeh looking for? Strings? some kind of Numpy num ? (I only know the bare basic of Numpy right now)

On Thu, Apr 23, 2015 at 3:19 PM, Chris Stehlik [email protected] wrote:

Hi Sarah,

Yes, I have done that. The entire file has individual donor info and I didn’t want to post that.

Thanks,

Chris

On Tuesday, April 21, 2015 at 8:31:02 PM UTC-7, Sarah Bird wrote:

Hi Chris,

Unfortunately it is hard to explore without the data. Are you, at least, able to post a csv of CountByDay?

you can get this by doing CountByDay.to_csv(‘filename’)

Sincerely,

Sarah Bird

On Mon, Apr 20, 2015 at 11:24 PM, Chris Stehlik [email protected] wrote:

Hello,

I can make a bar chart from a pandas groupby object using the pandas .plot() method, which calls matplotlib.
The Bokeh docs say that the bar chart function will take a pandas dataframe, but when i turn that same groupby object into a dataframe, using pandas DataFrame() to give me a dataframe with one index and one data columns,
I get an error. TypeError: cannot concatenate ‘str’ and ‘numpy.int64’ objects
I have included the Ipython Notebook I am working on. I can’t upload the data file it gets data from, but just looking at it without running it should be enough to see the problem. I first do a matplotlib bar chart and then try to do one with Bokeh. Any thoughts on what I am doing wrong would be appreciated.

Chris

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/900b63b4-2a1f-43b5-a1d8-3f0e034d150a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/AslswU4uPkA/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e9665068-3ecd-4338-820d-a5ba77024182%40continuum.io.

Hi Chris -

I think the problem may be related to some weirdness about encoding int64 values into JSON (for plotting) on some Windows machines (ref issue #573). I’m guessing the saving to and reading from csv is changing the dataframe dtype and fixing the problem.

Can you try changing the dataframe dtype to int32 like below and then calling the Bar function?

...
import numpy as np
df = df.astype(np.int32)
p = Bar(df)
show(p)
···

On Friday, April 24, 2015 at 3:24:04 AM UTC-5, Fabio Pliger wrote:

Hi Chris,

This should be a bug. I’ve opened an issue here.

Thanks

Fabio

On Friday, April 24, 2015 at 12:44:31 AM UTC+2, Chris Stehlik wrote:

Ok,

So quick experimentation shows that when I save CountByDay to csv and then read it back, Bokeh makes a bar chart just fine.
This suggests that the issue is the type of variable of the number data that is the problem. What is Bokeh looking for? Strings? some kind of Numpy num ? (I only know the bare basic of Numpy right now)

On Thu, Apr 23, 2015 at 3:19 PM, Chris Stehlik [email protected] wrote:

Hi Sarah,

Yes, I have done that. The entire file has individual donor info and I didn’t want to post that.

Thanks,

Chris

On Tuesday, April 21, 2015 at 8:31:02 PM UTC-7, Sarah Bird wrote:

Hi Chris,

Unfortunately it is hard to explore without the data. Are you, at least, able to post a csv of CountByDay?

you can get this by doing CountByDay.to_csv(‘filename’)

Sincerely,

Sarah Bird

On Mon, Apr 20, 2015 at 11:24 PM, Chris Stehlik [email protected] wrote:

Hello,

I can make a bar chart from a pandas groupby object using the pandas .plot() method, which calls matplotlib.
The Bokeh docs say that the bar chart function will take a pandas dataframe, but when i turn that same groupby object into a dataframe, using pandas DataFrame() to give me a dataframe with one index and one data columns,
I get an error. TypeError: cannot concatenate ‘str’ and ‘numpy.int64’ objects
I have included the Ipython Notebook I am working on. I can’t upload the data file it gets data from, but just looking at it without running it should be enough to see the problem. I first do a matplotlib bar chart and then try to do one with Bokeh. Any thoughts on what I am doing wrong would be appreciated.

Chris

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/900b63b4-2a1f-43b5-a1d8-3f0e034d150a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/AslswU4uPkA/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e9665068-3ecd-4338-820d-a5ba77024182%40continuum.io.

If I did it right, it’s still a problem. Here is the example notebook that I added your changes to. It still gives an error ‘cannot concatenate ‘str’ and ‘numpy.int64’ objects’ even though the columns are
now int32 dtypes. I have attached the edited Notebook to the Google Groups post,

Hi Chris -

I think the problem may be related to some weirdness about encoding int64 values into JSON (for plotting) on some Windows machines (ref issue #573). I’m guessing the saving to and reading from csv is changing the dataframe dtype and fixing the problem.

Can you try changing the dataframe dtype to int32 like below and then calling the Bar function?

...
import numpy as np
df = df.astype(np.int32)
p = Bar(df)
show(p)

Hi Chris,

This should be a bug. I’ve opened an issue here.

Thanks

Fabio

Ok,

So quick experimentation shows that when I save CountByDay to csv and then read it back, Bokeh makes a bar chart just fine.
This suggests that the issue is the type of variable of the number data that is the problem. What is Bokeh looking for? Strings? some kind of Numpy num ? (I only know the bare basic of Numpy right now)

Hi Sarah,

Yes, I have done that. The entire file has individual donor info and I didn’t want to post that.

Thanks,

Chris

Hi Chris,

Unfortunately it is hard to explore without the data. Are you, at least, able to post a csv of CountByDay?

you can get this by doing CountByDay.to_csv(‘filename’)

Sincerely,

Sarah Bird

Hello,

I can make a bar chart from a pandas groupby object using the pandas .plot() method, which calls matplotlib.
The Bokeh docs say that the bar chart function will take a pandas dataframe, but when i turn that same groupby object into a dataframe, using pandas DataFrame() to give me a dataframe with one index and one data columns,
I get an error. TypeError: cannot concatenate ‘str’ and ‘numpy.int64’ objects
I have included the Ipython Notebook I am working on. I can’t upload the data file it gets data from, but just looking at it without running it should be enough to see the problem. I first do a matplotlib bar chart and then try to do one with Bokeh. Any thoughts on what I am doing wrong would be appreciated.

Chris

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/900b63b4-2a1f-43b5-a1d8-3f0e034d150a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/AslswU4uPkA/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e9665068-3ecd-4338-820d-a5ba77024182%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Pledges charts bokeh.ipynb (1.47 MB)

···

On Wednesday, June 10, 2015 at 9:09:15 PM UTC-7, Chris Stehlik wrote:

On Wednesday, June 3, 2015 at 4:13:05 PM UTC-7, [email protected] wrote:

On Friday, April 24, 2015 at 3:24:04 AM UTC-5, Fabio Pliger wrote:

On Friday, April 24, 2015 at 12:44:31 AM UTC+2, Chris Stehlik wrote:

On Thu, Apr 23, 2015 at 3:19 PM, Chris Stehlik [email protected] wrote:

On Tuesday, April 21, 2015 at 8:31:02 PM UTC-7, Sarah Bird wrote:

On Mon, Apr 20, 2015 at 11:24 PM, Chris Stehlik [email protected] wrote: