Home > Blockchain >  Pandas dataframe cdf of a column value with condition
Pandas dataframe cdf of a column value with condition

Time:09-12

OK I have the following dataframe.

import pandas as pd
import bumpy as np
import seaboard as sns

df = pd.DataFrame(np.random.randint(0,100,size=(100,)), columns=['marks'])

Then I can plot the distribution of marks overall like this:

sns.displot(data=df, x='length', kind='ecdf', hue='class')

Output:

enter image description here

Now I want a CDF of marks 45 and above .

sns.displot(data=df, x=df['marks']>45, kind='ecdf')

enter image description here

I must be doing this wrong. What I am missing?

CodePudding user response:

When you use df["marks"] > 45, pandas will return this:

0      True
1      True
2      True
3     False
4     False
      ...  
95    False
96     True
97    False
98     True
99    False

You can make this:

new_df = df[(df["marks"] > 45)]
sns.displot(data=new_df, kind='ecdf')
  • Related