Python Script using pandas to plot histograms between the features


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


#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)



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.


Posted 2019-06-15T10:26:36.650

Reputation: 63

Add after that line – Aditya – 2019-06-15T10:42:14.350

I meant use seaborn or something like that for the plot and then add explicitly that – Aditya – 2019-06-15T10:47:12.193



cols = list(df.columns.values) 
for val in cols:
        df.groupby('Survived')[val].hist(alpha = 0.2)

just add in the end it would create histogram for all columns


Posted 2019-06-15T10:26:36.650

Reputation: 111