2

I am trying to plot integer columns of dataframe. I am trying by following way

for i in df:
    if df[i].dtypes == 'int64':
        df[i].plot.kde()

But it is plotting all in the same graph. I am new to it and would like to know how can I do it?

Mr. T
  • 11,960
  • 10
  • 32
  • 54
S.Dasgupta
  • 61
  • 9
  • This answer may help your question :[https://stackoverflow.com/questions/22483588/how-can-i-plot-separate-pandas-dataframes-as-subplots](https://stackoverflow.com/questions/22483588/how-can-i-plot-separate-pandas-dataframes-as-subplots) `df.select_dtypes(include=["integer"]).columns.size` calculates your axis size. – Ceyhun Jul 26 '18 at 11:08
  • DO you want one graph per time, subplots?.. – Joe Jul 26 '18 at 11:10
  • I would like to have distribution of each column data in one figure – S.Dasgupta Jul 26 '18 at 11:20
  • 1
    Again, we don't know what df contains and what your desired output is. Please edit your question and provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). You probably simply have to add a "plt.legend() plt.show()" after the loop to get your desired output. – Mr. T Jul 27 '18 at 11:02

2 Answers2

1

Just try to add plot option in your loop:

for i in df: 
    if df[i].dtypes == 'int64': 
        df[i].plot.kde()
        plt.show()
paveltr
  • 474
  • 1
  • 8
  • 22
0

If I understand correctly, you need :

df[(df.dtypes == 'int64').index].plot.kde(subplots=True)
#we find the columns that have int64 values and plot all columns in different plot

Using your code : all plots together using above code all plots together

Krishna
  • 6,107
  • 2
  • 40
  • 43