python - How do I select and store columns greater than a number in pandas? -
i have pandas dataframe column of integers. want rows containing numbers greater 10. able evaluate true or false not actual value, doing:
df['ints'] = df['ints'] > 10
i don't use python i'm going round in circles this.
i've spent 20 minutes googling haven't been able find need....
edit:
observationid recordkey gridreference sitekey sitename featurekey startdate enddate ptaxonversionkey taxonname authority commonname ints 0 463166539 1767 sm90 nan nan 150161 12/02/2006 12/02/2006 nbnsys0100004720 pipistrellus pygmaeus (leach, 1825) soprano pipistrelle 2006 1 463166623 4325 tl65 nan nan 168651 21/12/2008 21/12/2008 nhmsys0020001355 pipistrellus pipistrellus sensu stricto (schreber, 1774) common pipistrelle 2008 2 463166624 4326 tl65 nan nan 168651 18/01/2009 18/01/2009 nhmsys0020001355 pipistrellus pipistrellus sensu stricto (schreber, 1774) common pipistrelle 2009 3 463166625 4327 tl65 nan nan 168651 15/02/2009 15/02/2009 nhmsys0020001355 pipistrellus pipistrellus sensu stricto (schreber, 1774) common pipistrelle 2009 4 463166626 4328 tl65 nan nan 168651 19/12/2009 19/12/2009 nhmsys0020001355 pipistrellus pipistrellus sensu stricto (schreber, 1774) common pipistrelle 2009
sample df:
in [79]: df = pd.dataframe(np.random.randint(5, 15, (10, 3)), columns=list('abc')) in [80]: df out[80]: b c 0 6 11 11 1 14 7 8 2 13 5 11 3 13 7 11 4 13 5 9 5 5 11 9 6 9 8 6 7 5 11 10 8 8 10 14 9 7 14 13
present rows b > 10
in [81]: df[df.b > 10] out[81]: b c 0 6 11 11 5 5 11 9 7 5 11 10 9 7 14 13
minimums (for columns) rows satisfying b > 10
condition
in [82]: df[df.b > 10].min() out[82]: 5 b 11 c 9 dtype: int32
minimum (for b
column) rows satisfying b > 10
condition
in [84]: df.loc[df.b > 10, 'b'].min() out[84]: 11
update: starting pandas 0.20.1 the .ix indexer deprecated, in favor of more strict .iloc , .loc indexers.
Comments
Post a Comment