-1

I'm trying to plot data based on values in two to three other columns. The below code works if I take out & df[df.Age > 50]. Is there a way to adjust the code to work? Thank you!

plt.figure(figsize = (15, 5))
plt.title(f"KDE Plot:", fontsize = 30, fontweight = 'bold')
ax = sns.kdeplot(
    df[df.OpenedLCInd== 1 ] & df[df.Age > 50]['APlusCreditTier'].dropna(),
    label = 'Opened Letter Check',
    lw = 2,
    legend = True
)
plt.legend = True
ax1 = sns.kdeplot(
    df[df.OpenedLCInd == 0]['APlusCreditTier'].dropna(), 
    label = 'No Open Letter Check', 
    lw = 2, legend = True
)
plt.tight_layout()
Alex
  • 6,610
  • 3
  • 20
  • 38
user14316330
  • 61
  • 1
  • 6

1 Answers1

2

Your conditional is wrong in the first kdeplot, it should be:

df[df.OpenedLCInd.eq(1) & df.Age.gt(50)]['APlusCreditTier'].dropna()

or

df[(df.OpenedLCInd== 1) & (df.Age > 50)]['APlusCreditTier'].dropna()

See the pandas docs for more information on subsetting your data.

Alex
  • 6,610
  • 3
  • 20
  • 38