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?

4
  • This answer may help your question :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. Commented Jul 26, 2018 at 11:08
  • DO you want one graph per time, subplots?.. Commented Jul 26, 2018 at 11:10
  • I would like to have distribution of each column data in one figure Commented Jul 26, 2018 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. You probably simply have to add a "plt.legend() plt.show()" after the loop to get your desired output. Commented Jul 27, 2018 at 11:02

2 Answers 2

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()
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.