pandas DataFrame set value on boolean mask

前端 未结 4 1235
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 20:07

I\'m trying to set a number of different in a pandas DataFrame all to the same value. I thought I understood boolean indexing for pandas, but I haven\'t found any resources

4条回答
  •  执念已碎
    2020-12-18 20:35

    pandas uses NaN to mark invalid or missing data and can be used across types, since your DataFrame as mixed int and string data types it will not accept the assignment to a single type (other than NaN) as this would create a mixed type (int and str) in B through an in-place assignment.

    @JohnE method using np.where creates a new DataFrame in which the type of column B is an object not a string as in the initial example.

提交回复
热议问题