Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create an array from a data frame, based off of conditions

I have a sample dataframe like;

df=pd.DataFrame({'degree_awarded':['yes','no','yes','yes',
                                 'yes','yes' ,'yes','no'],
                  'avg_score':[78,87,94,55,68,76,78,8]
                })

degree_awarded avg_score
yes 78
no 87
yes 94
yes 55

I’d like to separate the ‘degree_awarded’ column into ‘degree_awarded’, ‘no_degree_awarded’ arrays with the relevant score for example

degree_awarded: [78, 94, 55]
no_degree_awarded: [87]

but I’m not sure how to do this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help would be appreciated, thanks for your time.

>Solution :

listScoreAwarded=list(df[df['degree_awarded']=='yes']['avg_score'])

listScoreNotAwarded=list(df[df['degree_awarded']=='no']['avg_score'])

Both these lists should work

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading