python - pandas dataframe.where misbehaving -
python - pandas dataframe.where misbehaving -
i'm trying implement function returns max @ each position of dataframe or series, minimizing nan.
in [217]: out[217]: 0 1 0 4 1 1 6 0 [2 rows x 2 columns] in [218]: b out[218]: 0 1 0 nan 3 1 3 nan [2 rows x 2 columns] in [219]: do_not_replace = b.isnull() | (a > b) in [220]: do_not_replace out[220]: 0 1 0 true false 1 true true [2 rows x 2 columns] in [221]: a.where(do_not_replace, b) out[221]: 0 1 0 4 3 1 1 0 [2 rows x 2 columns] in [222]: expected out[222]: 0 1 0 4 3 1 6 0 [2 rows x 2 columns] in [223]: pd.__version__ out[223]: '0.13.1' i imagine there other ways implement function, i'm unable figure out behavior. mean, 1 coming from? think logic sound. misinterpreting how function works?
this where internally. think might transpositional bug. bug fixed here. turns out symmetric dataframe , passed frame required reproduce. subtle. note other form of indexing (below) uses different method that's inplace ok.
in [56]: a[~do_not_replace] = b in [57]: out[57]: 0 1 0 4 3 1 6 0 note: has been fixed in master/0.14.1.
python numpy pandas
Comments
Post a Comment