DOC: Adding new columns in a DataFrame of Nullable type might be better explained #49201
Closed
1 task done
Labels
Milestone
Pandas version checks
main
hereLocation of the documentation
https://pandas.pydata.org/pandas-docs/stable/user_guide/integer_na.html
Documentation problem
When adding a new column to an exisitng dataframe using pd.NA is tricky.
Adding a new column of type
datetime64[ns]
works as expected usingpd.NaT
:However, adding a column using
pd.NA
produces a column of typeobject
:That is exactly what it is asked for but not what I was naively expecting (a column of type
Int64
)This is logical as the
pd.NA
type is used also forstring
andboolean
types and maybe others.The best way I found to create a new, empty column of a desired nullable type is the following:
Suggested fix for documentation
I think it will be enough to mention this point as an additional entry in the page from nullable datatypes, to show that creating a column initialised with
pd.NA
is not different to creating a column with any other, non numeric python object.The text was updated successfully, but these errors were encountered: