Closed
Description
import numpy as np
import pandas as pd
pd.show_versions()
INSTALLED VERSIONS
------------------
commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.0.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 40.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.2.8
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.1.3
numexpr : None
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : 1.2.8
numba : None
df = pd.DataFrame([[1,2], [3,np.nan]], index= ['a', 'b'], columns=['A', 'B']).convert_dtypes()
df
A | B | |
---|---|---|
a | 1 | 2 |
b | 3 | <NA> |
df.dtypes
A Int64
B Int64
dtype: object
df.diff(axis=0)
A | B | |
---|---|---|
a | <NA> | <NA> |
b | 2 | <NA> |
df.diff(axis=1)
A | B | |
---|---|---|
a | <NA> | <NA> |
b | 2 | <NA> |
Conversion to float fixes the issue
df = df.astype(float)
df
A | B | |
---|---|---|
a | 1.0 | 2.0 |
b | 3.0 | NaN |
df.diff(axis=1)
A | B | |
---|---|---|
a | NaN | 1.0 |
b | NaN | NaN |