Stacked Bokeh plot dont run
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am practicing with Bokeh but I still fail, I get the data from a xls file, then the data is filtering and group by sex (Female and Male).
Cantidad
Sexo
FEMENINO 123
MASCULINO 352
this is an output when I print the columns wich I'll work:
print df = df[['Sexo','Movil Victima','Cantidad']]
Sexo Movil Victima Cantidad
1 MASCULINO MOTO 1
2 FEMENINO MOTO 1
3 MASCULINO A PIE 1
4 MASCULINO MOTO 1
5 FEMENINO A PIE 1
6 MASCULINO A PIE 1
7 FEMENINO A PIE 1
8 FEMENINO A PIE 1
9 MASCULINO A PIE 1
10 FEMENINO A PIE 1
11 FEMENINO A PIE 1
12 MASCULINO BICICLETA 1
13 FEMENINO A PIE 1
and this is my code:
import pandas as pd
from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral3
output_file('stackedBar-Sexo_tipoMovil.html')
df = pd.read_excel(r'C:UsersciscoDesktopProyectoVtransitohomicidios-accidentes-transito-2018_1.xls')
filter = df['Sexo'].isin(('MASCULINO','FEMENINO'))
df = df[filter]
grouped = df.groupby('Sexo')['Cantidad', 'Movil Victima', 'Profesion'].sum()
print(df)
source = ColumnDataSource(grouped)
countries = source.data['Sexo'].tolist()
p = figure(x_range=countries)
p.vbar_stack(stackers=['Movil Victima'], x='Sexo', source=source, legend = ['Movil Victima'], width=0.5, color=Spectral3)
p.title.text ='Muertes Genero por Tipo Movil'
p.legend.location = 'top_left'
p.xaxis.axis_label = 'Sexo'
p.xgrid.grid_line_color = None #remove the x grid lines
p.yaxis.axis_label = 'Cantidad'
show(p)
The output prints that there is an error in line 23:
p.vbar_stack(stackers=['Movil Victima'], x='Sexo', source=source, legend = ['Movil Victima'], width=0.5, color=Spectral3)
The error is:
_stack
raise ValueError("Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: %r" % sorted(list(lengths)))
ValueError: Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [1, 3].
Wich is the error? i cant see it.
Thanks.
python pandas bokeh
add a comment |
I am practicing with Bokeh but I still fail, I get the data from a xls file, then the data is filtering and group by sex (Female and Male).
Cantidad
Sexo
FEMENINO 123
MASCULINO 352
this is an output when I print the columns wich I'll work:
print df = df[['Sexo','Movil Victima','Cantidad']]
Sexo Movil Victima Cantidad
1 MASCULINO MOTO 1
2 FEMENINO MOTO 1
3 MASCULINO A PIE 1
4 MASCULINO MOTO 1
5 FEMENINO A PIE 1
6 MASCULINO A PIE 1
7 FEMENINO A PIE 1
8 FEMENINO A PIE 1
9 MASCULINO A PIE 1
10 FEMENINO A PIE 1
11 FEMENINO A PIE 1
12 MASCULINO BICICLETA 1
13 FEMENINO A PIE 1
and this is my code:
import pandas as pd
from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral3
output_file('stackedBar-Sexo_tipoMovil.html')
df = pd.read_excel(r'C:UsersciscoDesktopProyectoVtransitohomicidios-accidentes-transito-2018_1.xls')
filter = df['Sexo'].isin(('MASCULINO','FEMENINO'))
df = df[filter]
grouped = df.groupby('Sexo')['Cantidad', 'Movil Victima', 'Profesion'].sum()
print(df)
source = ColumnDataSource(grouped)
countries = source.data['Sexo'].tolist()
p = figure(x_range=countries)
p.vbar_stack(stackers=['Movil Victima'], x='Sexo', source=source, legend = ['Movil Victima'], width=0.5, color=Spectral3)
p.title.text ='Muertes Genero por Tipo Movil'
p.legend.location = 'top_left'
p.xaxis.axis_label = 'Sexo'
p.xgrid.grid_line_color = None #remove the x grid lines
p.yaxis.axis_label = 'Cantidad'
show(p)
The output prints that there is an error in line 23:
p.vbar_stack(stackers=['Movil Victima'], x='Sexo', source=source, legend = ['Movil Victima'], width=0.5, color=Spectral3)
The error is:
_stack
raise ValueError("Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: %r" % sorted(list(lengths)))
ValueError: Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [1, 3].
Wich is the error? i cant see it.
Thanks.
python pandas bokeh
Your example dataframe does not have a columnProfesion
, so I can't reproduce your code.
– Edgar Ramírez Mondragón
Nov 27 '18 at 23:25
add a comment |
I am practicing with Bokeh but I still fail, I get the data from a xls file, then the data is filtering and group by sex (Female and Male).
Cantidad
Sexo
FEMENINO 123
MASCULINO 352
this is an output when I print the columns wich I'll work:
print df = df[['Sexo','Movil Victima','Cantidad']]
Sexo Movil Victima Cantidad
1 MASCULINO MOTO 1
2 FEMENINO MOTO 1
3 MASCULINO A PIE 1
4 MASCULINO MOTO 1
5 FEMENINO A PIE 1
6 MASCULINO A PIE 1
7 FEMENINO A PIE 1
8 FEMENINO A PIE 1
9 MASCULINO A PIE 1
10 FEMENINO A PIE 1
11 FEMENINO A PIE 1
12 MASCULINO BICICLETA 1
13 FEMENINO A PIE 1
and this is my code:
import pandas as pd
from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral3
output_file('stackedBar-Sexo_tipoMovil.html')
df = pd.read_excel(r'C:UsersciscoDesktopProyectoVtransitohomicidios-accidentes-transito-2018_1.xls')
filter = df['Sexo'].isin(('MASCULINO','FEMENINO'))
df = df[filter]
grouped = df.groupby('Sexo')['Cantidad', 'Movil Victima', 'Profesion'].sum()
print(df)
source = ColumnDataSource(grouped)
countries = source.data['Sexo'].tolist()
p = figure(x_range=countries)
p.vbar_stack(stackers=['Movil Victima'], x='Sexo', source=source, legend = ['Movil Victima'], width=0.5, color=Spectral3)
p.title.text ='Muertes Genero por Tipo Movil'
p.legend.location = 'top_left'
p.xaxis.axis_label = 'Sexo'
p.xgrid.grid_line_color = None #remove the x grid lines
p.yaxis.axis_label = 'Cantidad'
show(p)
The output prints that there is an error in line 23:
p.vbar_stack(stackers=['Movil Victima'], x='Sexo', source=source, legend = ['Movil Victima'], width=0.5, color=Spectral3)
The error is:
_stack
raise ValueError("Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: %r" % sorted(list(lengths)))
ValueError: Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [1, 3].
Wich is the error? i cant see it.
Thanks.
python pandas bokeh
I am practicing with Bokeh but I still fail, I get the data from a xls file, then the data is filtering and group by sex (Female and Male).
Cantidad
Sexo
FEMENINO 123
MASCULINO 352
this is an output when I print the columns wich I'll work:
print df = df[['Sexo','Movil Victima','Cantidad']]
Sexo Movil Victima Cantidad
1 MASCULINO MOTO 1
2 FEMENINO MOTO 1
3 MASCULINO A PIE 1
4 MASCULINO MOTO 1
5 FEMENINO A PIE 1
6 MASCULINO A PIE 1
7 FEMENINO A PIE 1
8 FEMENINO A PIE 1
9 MASCULINO A PIE 1
10 FEMENINO A PIE 1
11 FEMENINO A PIE 1
12 MASCULINO BICICLETA 1
13 FEMENINO A PIE 1
and this is my code:
import pandas as pd
from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral3
output_file('stackedBar-Sexo_tipoMovil.html')
df = pd.read_excel(r'C:UsersciscoDesktopProyectoVtransitohomicidios-accidentes-transito-2018_1.xls')
filter = df['Sexo'].isin(('MASCULINO','FEMENINO'))
df = df[filter]
grouped = df.groupby('Sexo')['Cantidad', 'Movil Victima', 'Profesion'].sum()
print(df)
source = ColumnDataSource(grouped)
countries = source.data['Sexo'].tolist()
p = figure(x_range=countries)
p.vbar_stack(stackers=['Movil Victima'], x='Sexo', source=source, legend = ['Movil Victima'], width=0.5, color=Spectral3)
p.title.text ='Muertes Genero por Tipo Movil'
p.legend.location = 'top_left'
p.xaxis.axis_label = 'Sexo'
p.xgrid.grid_line_color = None #remove the x grid lines
p.yaxis.axis_label = 'Cantidad'
show(p)
The output prints that there is an error in line 23:
p.vbar_stack(stackers=['Movil Victima'], x='Sexo', source=source, legend = ['Movil Victima'], width=0.5, color=Spectral3)
The error is:
_stack
raise ValueError("Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: %r" % sorted(list(lengths)))
ValueError: Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [1, 3].
Wich is the error? i cant see it.
Thanks.
python pandas bokeh
python pandas bokeh
edited Nov 27 '18 at 2:15
JUAN RAMIREZ
asked Nov 26 '18 at 21:21
JUAN RAMIREZJUAN RAMIREZ
84
84
Your example dataframe does not have a columnProfesion
, so I can't reproduce your code.
– Edgar Ramírez Mondragón
Nov 27 '18 at 23:25
add a comment |
Your example dataframe does not have a columnProfesion
, so I can't reproduce your code.
– Edgar Ramírez Mondragón
Nov 27 '18 at 23:25
Your example dataframe does not have a column
Profesion
, so I can't reproduce your code.– Edgar Ramírez Mondragón
Nov 27 '18 at 23:25
Your example dataframe does not have a column
Profesion
, so I can't reproduce your code.– Edgar Ramírez Mondragón
Nov 27 '18 at 23:25
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53489262%2fstacked-bokeh-plot-dont-run%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53489262%2fstacked-bokeh-plot-dont-run%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your example dataframe does not have a column
Profesion
, so I can't reproduce your code.– Edgar Ramírez Mondragón
Nov 27 '18 at 23:25