python - Conditional Logic on Pandas DataFrame -



python - Conditional Logic on Pandas DataFrame -

how apply conditional logic pandas dataframe.

see dataframe shown below,

info desired_output 0 1 false 1 2 false 2 3 true 3 4 true

my original info show in 'data' column , desired_output shown next it. if number in 'data' below 2.5, desired_output false.

i apply loop , re-construct dataframe... 'un-pythonic'

just compare column value:

in [9]: df = pandas.dataframe([1,2,3,4], columns=["data"]) in [10]: df out[10]: info 0 1 1 2 2 3 3 4 in [11]: df["desired"] = df["data"] > 2.5 in [11]: df out[12]: info desired 0 1 false 1 2 false 2 3 true 3 4 true

python pandas

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

r - url in CRAN extension manual -

asp.net - .NET Control.ID property inconsistency -