0
$\begingroup$

I am working around with data from Kaggle : Titanic Competition dataset.

Script

#cols : List of all column header
cols = list(df.columns.values) 
#script to plot histograms of all columns with respect to column: "Survived"
for val in cols:
       df.groupby('Survived')[val].hist(alpha = 0.2)

Code of importance (COI)

df.groupby('Survived')['Age'].hist(alpha = 0.3)

Output

output

The COI works but the Script is not working. The script will help to plot all the histograms in one go without manually inserting the column in the COI.

  1. The script is running indefinetly.
  2. The COI also runs indefinetly but once I execute the following code:
df.groupby('Survived').Age.hist(alpha = 0.2) #This runs flawlessly

COI runs perfectly. (Not able to figure out why).

  1. The scripts are written in Kaggel Kernel.

Given the above details, please help me figure out a way to achieve the above script either by making improvements to the Script or an alternate way of doing the same.

$\endgroup$
  • $\begingroup$ Add plt.show() after that line $\endgroup$ – Aditya Jun 15 '19 at 10:42
  • $\begingroup$ I meant use seaborn or something like that for the plot and then add explicitly that $\endgroup$ – Aditya Jun 15 '19 at 10:47
1
$\begingroup$
cols = list(df.columns.values) 
for val in cols:
        df.groupby('Survived')[val].hist(alpha = 0.2)
        plt.show()

just add plt.show() in the end it would create histogram for all columns

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.