vendredi 18 novembre 2016

What would be the nicest way to re-write this conditionals?

Given that the following lines of code do get the job done, what would be the nicest more pythonic way to re-write this?

if df['A'].sum() < 1:
    sample = df
if df['A'].sum() >= 1:
    sample = df[df['A'] == 1]

if df['B'].sum() < 1:
    sample = sample
if df['B'].sum() >= 1:    
    sample = sample[sample['B'] == 1]

if df['C'].sum() < 1:
    sample = sample
if df['C'].sum() >= 1: 
    sample = sample[sample['C'] == 1]

Aucun commentaire:

Enregistrer un commentaire