ENH: add option to get nullable dtypes to pd.read_csv · Issue #36712 · pandas-dev/pandas (original) (raw)
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- (optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
In[2]: import pandas as pd In[3]: s = pd.Series([1, 2, None, 3], dtype=pd.UInt64Dtype()) In[4]: s Out[4]: 0 1 1 2 2 3 3 dtype: UInt64 In[5]: df = pd.DataFrame({"a":s}) In[6]: df Out[6]: a 0 1 1 2 2 3 3 In[7]: df.to_csv('temp.csv') In[8]: pd.read_csv('temp.csv') Out[8]: Unnamed: 0 a 0 0 1.0 1 1 2.0 2 2 NaN 3 3 3.0
Problem description
While reading csv, pandas should likely read in the above dataframe column as a nullable integer dtype instead of converting to floating data type.
Expected Output
pd.read_csv('temp.csv') Out[8]: Unnamed: 0 a 0 0 1 1 1 2 2 2 3 3 3
Output of pd.show_versions()
INSTALLED VERSIONS
commit : 2a7d332
python : 3.7.8.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-48-generic
Version : #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.2
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20200917
Cython : 0.29.21
pytest : 6.0.2
hypothesis : 5.28.0
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.2
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.51.2