Code
>>> df
A B C
0 1.739232 1.369457 -0.546500
1 0.340898 NaN 0.518132
2 NaN NaN NaN
3 1.868215 0.803584 -0.333043
>>> df.loc[~df.isnull().all(axis=1),'B'].fillna(99.9,inplace=True)
>>> df
A B C
0 1.739232 1.369457 -0.546500
1 0.340898 NaN 0.518132
2 NaN NaN NaN
3 1.868215 0.803584 -0.333043
Problem description
I am trying to fill some null values in a column but not all using boolean indexing. But fillna
doesn't seem to work in that case. What's the correct way to achieve it?
Expected Output
>>> df
A B C
0 1.739232 1.369457 -0.546500
1 0.340898 99.9 0.518132
2 NaN NaN NaN
3 1.868215 0.803584 -0.333043
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Darwin
OS-release: 16.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 27.2.0
Cython: None
numpy: 1.12.1
scipy: 0.19.1
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
Comment From: tdpetrou
You need to post this to StackOverflow and tag it with pandas. Post it there and someone will answer it within 15 minutes. Come to github when you find a bug not for a usage question.
Comment From: jreback
your inplace=True
is the problem as you are modifying a copy.
but @tdpetrou is right, SO is the first place to go.