plot a histogram over specific columns of a dataframe pandas












0















I have a dataframe with a cloumn called rel_positive, and a cloumn called len_text_celaned
I want to plot a histogramm where rel_positive is displayed as a function of len_text_celaned.



I tried it with this striaghtforward approach:



df_rel.rel_positive.hist(df_rel.len_text_celaned)


as far as i understand the first argument in the brackets of df.hist is the x-values?
but it retruns me an array rather than a plot.



array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000020AF0104630>,
<matplotlib.axes._subplots.AxesSubplot object at 0x0000020AF48A4EF0>,


Maybe im overseeing a very stupid mistake?
or is there another way?



EDIT:
apperantly it looks like the array contains several lists










share|improve this question

























  • Are you working in a Jupyter Notebook? If so, try running the IPython magic command %matplotlib inline, then running your plotting code again.

    – Peter Leimbigler
    Nov 24 '18 at 19:01











  • yes i do, after calling your command i still get the same results..

    – user10395806
    Nov 24 '18 at 19:07
















0















I have a dataframe with a cloumn called rel_positive, and a cloumn called len_text_celaned
I want to plot a histogramm where rel_positive is displayed as a function of len_text_celaned.



I tried it with this striaghtforward approach:



df_rel.rel_positive.hist(df_rel.len_text_celaned)


as far as i understand the first argument in the brackets of df.hist is the x-values?
but it retruns me an array rather than a plot.



array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000020AF0104630>,
<matplotlib.axes._subplots.AxesSubplot object at 0x0000020AF48A4EF0>,


Maybe im overseeing a very stupid mistake?
or is there another way?



EDIT:
apperantly it looks like the array contains several lists










share|improve this question

























  • Are you working in a Jupyter Notebook? If so, try running the IPython magic command %matplotlib inline, then running your plotting code again.

    – Peter Leimbigler
    Nov 24 '18 at 19:01











  • yes i do, after calling your command i still get the same results..

    – user10395806
    Nov 24 '18 at 19:07














0












0








0








I have a dataframe with a cloumn called rel_positive, and a cloumn called len_text_celaned
I want to plot a histogramm where rel_positive is displayed as a function of len_text_celaned.



I tried it with this striaghtforward approach:



df_rel.rel_positive.hist(df_rel.len_text_celaned)


as far as i understand the first argument in the brackets of df.hist is the x-values?
but it retruns me an array rather than a plot.



array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000020AF0104630>,
<matplotlib.axes._subplots.AxesSubplot object at 0x0000020AF48A4EF0>,


Maybe im overseeing a very stupid mistake?
or is there another way?



EDIT:
apperantly it looks like the array contains several lists










share|improve this question
















I have a dataframe with a cloumn called rel_positive, and a cloumn called len_text_celaned
I want to plot a histogramm where rel_positive is displayed as a function of len_text_celaned.



I tried it with this striaghtforward approach:



df_rel.rel_positive.hist(df_rel.len_text_celaned)


as far as i understand the first argument in the brackets of df.hist is the x-values?
but it retruns me an array rather than a plot.



array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000020AF0104630>,
<matplotlib.axes._subplots.AxesSubplot object at 0x0000020AF48A4EF0>,


Maybe im overseeing a very stupid mistake?
or is there another way?



EDIT:
apperantly it looks like the array contains several lists







python python-3.x pandas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 9 '18 at 16:34









Cœur

18.5k9110148




18.5k9110148










asked Nov 24 '18 at 17:32









user10395806user10395806

356




356













  • Are you working in a Jupyter Notebook? If so, try running the IPython magic command %matplotlib inline, then running your plotting code again.

    – Peter Leimbigler
    Nov 24 '18 at 19:01











  • yes i do, after calling your command i still get the same results..

    – user10395806
    Nov 24 '18 at 19:07



















  • Are you working in a Jupyter Notebook? If so, try running the IPython magic command %matplotlib inline, then running your plotting code again.

    – Peter Leimbigler
    Nov 24 '18 at 19:01











  • yes i do, after calling your command i still get the same results..

    – user10395806
    Nov 24 '18 at 19:07

















Are you working in a Jupyter Notebook? If so, try running the IPython magic command %matplotlib inline, then running your plotting code again.

– Peter Leimbigler
Nov 24 '18 at 19:01





Are you working in a Jupyter Notebook? If so, try running the IPython magic command %matplotlib inline, then running your plotting code again.

– Peter Leimbigler
Nov 24 '18 at 19:01













yes i do, after calling your command i still get the same results..

– user10395806
Nov 24 '18 at 19:07





yes i do, after calling your command i still get the same results..

– user10395806
Nov 24 '18 at 19:07












1 Answer
1






active

oldest

votes


















0














According to pandas documentation (pandas.DataFrame.hist()), the first argument is column:





  • column: string or sequence. If passed, will be used to limit data to a subset of columns.


I will give an example based in your question:



import pandas as pd
df_rel = pd.DataFrame({'rel_positive': ['Y', 'N', 'Y', 'N', 'Y', 'Y', 'Y', 'N', 'N', 'Y'] ,
'len_text_celaned': [3,1,2,1,3,5,2,3,4,4]})
df_rel.len_text_celaned.hist(df_rel.rel_positive)


Since the rel_positive column has 2 values ('Y' or 'N'), the df_rel.len_text_celaned.hist(column=df_rel.rel_positive) will plot 1 histogram for each rel_positive value, with the referred len_text_celaned values.



Check the resulting plot in this link






share|improve this answer
























  • ah that explains why i only get the array... but still how can i then solve my problem?

    – user10395806
    Nov 24 '18 at 19:32











  • Try to plot the first index, like df_rel.len_text_celaned.hist(df_rel.rel_positive)[0]. Check if it works

    – fernandho
    Nov 24 '18 at 19:58











  • no doesnt work, i get an array of one list returned, looks like the one provided above

    – user10395806
    Nov 24 '18 at 21:56













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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460718%2fplot-a-histogram-over-specific-columns-of-a-dataframe-pandas%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














According to pandas documentation (pandas.DataFrame.hist()), the first argument is column:





  • column: string or sequence. If passed, will be used to limit data to a subset of columns.


I will give an example based in your question:



import pandas as pd
df_rel = pd.DataFrame({'rel_positive': ['Y', 'N', 'Y', 'N', 'Y', 'Y', 'Y', 'N', 'N', 'Y'] ,
'len_text_celaned': [3,1,2,1,3,5,2,3,4,4]})
df_rel.len_text_celaned.hist(df_rel.rel_positive)


Since the rel_positive column has 2 values ('Y' or 'N'), the df_rel.len_text_celaned.hist(column=df_rel.rel_positive) will plot 1 histogram for each rel_positive value, with the referred len_text_celaned values.



Check the resulting plot in this link






share|improve this answer
























  • ah that explains why i only get the array... but still how can i then solve my problem?

    – user10395806
    Nov 24 '18 at 19:32











  • Try to plot the first index, like df_rel.len_text_celaned.hist(df_rel.rel_positive)[0]. Check if it works

    – fernandho
    Nov 24 '18 at 19:58











  • no doesnt work, i get an array of one list returned, looks like the one provided above

    – user10395806
    Nov 24 '18 at 21:56


















0














According to pandas documentation (pandas.DataFrame.hist()), the first argument is column:





  • column: string or sequence. If passed, will be used to limit data to a subset of columns.


I will give an example based in your question:



import pandas as pd
df_rel = pd.DataFrame({'rel_positive': ['Y', 'N', 'Y', 'N', 'Y', 'Y', 'Y', 'N', 'N', 'Y'] ,
'len_text_celaned': [3,1,2,1,3,5,2,3,4,4]})
df_rel.len_text_celaned.hist(df_rel.rel_positive)


Since the rel_positive column has 2 values ('Y' or 'N'), the df_rel.len_text_celaned.hist(column=df_rel.rel_positive) will plot 1 histogram for each rel_positive value, with the referred len_text_celaned values.



Check the resulting plot in this link






share|improve this answer
























  • ah that explains why i only get the array... but still how can i then solve my problem?

    – user10395806
    Nov 24 '18 at 19:32











  • Try to plot the first index, like df_rel.len_text_celaned.hist(df_rel.rel_positive)[0]. Check if it works

    – fernandho
    Nov 24 '18 at 19:58











  • no doesnt work, i get an array of one list returned, looks like the one provided above

    – user10395806
    Nov 24 '18 at 21:56
















0












0








0







According to pandas documentation (pandas.DataFrame.hist()), the first argument is column:





  • column: string or sequence. If passed, will be used to limit data to a subset of columns.


I will give an example based in your question:



import pandas as pd
df_rel = pd.DataFrame({'rel_positive': ['Y', 'N', 'Y', 'N', 'Y', 'Y', 'Y', 'N', 'N', 'Y'] ,
'len_text_celaned': [3,1,2,1,3,5,2,3,4,4]})
df_rel.len_text_celaned.hist(df_rel.rel_positive)


Since the rel_positive column has 2 values ('Y' or 'N'), the df_rel.len_text_celaned.hist(column=df_rel.rel_positive) will plot 1 histogram for each rel_positive value, with the referred len_text_celaned values.



Check the resulting plot in this link






share|improve this answer













According to pandas documentation (pandas.DataFrame.hist()), the first argument is column:





  • column: string or sequence. If passed, will be used to limit data to a subset of columns.


I will give an example based in your question:



import pandas as pd
df_rel = pd.DataFrame({'rel_positive': ['Y', 'N', 'Y', 'N', 'Y', 'Y', 'Y', 'N', 'N', 'Y'] ,
'len_text_celaned': [3,1,2,1,3,5,2,3,4,4]})
df_rel.len_text_celaned.hist(df_rel.rel_positive)


Since the rel_positive column has 2 values ('Y' or 'N'), the df_rel.len_text_celaned.hist(column=df_rel.rel_positive) will plot 1 histogram for each rel_positive value, with the referred len_text_celaned values.



Check the resulting plot in this link







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 19:25









fernandhofernandho

1




1













  • ah that explains why i only get the array... but still how can i then solve my problem?

    – user10395806
    Nov 24 '18 at 19:32











  • Try to plot the first index, like df_rel.len_text_celaned.hist(df_rel.rel_positive)[0]. Check if it works

    – fernandho
    Nov 24 '18 at 19:58











  • no doesnt work, i get an array of one list returned, looks like the one provided above

    – user10395806
    Nov 24 '18 at 21:56





















  • ah that explains why i only get the array... but still how can i then solve my problem?

    – user10395806
    Nov 24 '18 at 19:32











  • Try to plot the first index, like df_rel.len_text_celaned.hist(df_rel.rel_positive)[0]. Check if it works

    – fernandho
    Nov 24 '18 at 19:58











  • no doesnt work, i get an array of one list returned, looks like the one provided above

    – user10395806
    Nov 24 '18 at 21:56



















ah that explains why i only get the array... but still how can i then solve my problem?

– user10395806
Nov 24 '18 at 19:32





ah that explains why i only get the array... but still how can i then solve my problem?

– user10395806
Nov 24 '18 at 19:32













Try to plot the first index, like df_rel.len_text_celaned.hist(df_rel.rel_positive)[0]. Check if it works

– fernandho
Nov 24 '18 at 19:58





Try to plot the first index, like df_rel.len_text_celaned.hist(df_rel.rel_positive)[0]. Check if it works

– fernandho
Nov 24 '18 at 19:58













no doesnt work, i get an array of one list returned, looks like the one provided above

– user10395806
Nov 24 '18 at 21:56







no doesnt work, i get an array of one list returned, looks like the one provided above

– user10395806
Nov 24 '18 at 21:56






















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460718%2fplot-a-histogram-over-specific-columns-of-a-dataframe-pandas%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin