Skip to content

indexed assignment does not work for dataframe #5938

Closed
@RayVR

Description

@RayVR
In [82]: d = {'a': range(4), 'b': list('ab..'), 'c': ['a', 'b', nan, 'd']}
In [83]: df = pd.DataFrame(d)
In [84]: df
Out[84]:
   a  b    c
0  0  a    a
1  1  b    b
2  2  .  NaN
3  3  .    d
In [85]: df[['c']][pd.isnull(df.c)] = df[['b']][pd.isnull(df.c)]
In [86]: df
Out[86]:
   a  b    c
0  0  a    a
1  1  b    b
2  2  .  NaN
3  3  .    d

In [87]: df['c'][pd.isnull(df.c)] = df[['b']][pd.isnull(df.c)]

In [88]: df
Out[88]:
   a  b  c
0  0  a  a
1  1  b  b
2  2  .  .
3  3  .  d

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions