-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Implement convert_dtypes #30929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
04b277b
82e62dc
dc1daa0
a9b477e
e54ad4f
8cc238d
f0ba92b
aebba66
40123c7
78be9b8
7bf4f51
f59a7d4
b85d135
26ffc26
888ac31
a6e10b0
34493a0
f990096
4c272ee
585df23
2efb8ea
8e4dfff
c80ce7d
0a331a4
8a5fcf3
39798fa
1e68d03
fa93a84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -806,7 +806,8 @@ dtype, it will use ``pd.NA``: | |
|
||
Currently, pandas does not yet use those data types by default (when creating | ||
a DataFrame or Series, or when reading in data), so you need to specify | ||
the dtype explicitly. | ||
the dtype explicitly. An easy way to convert to those dtypes is explained | ||
:ref:`here <missing_data.NA.Conversion>`. | ||
|
||
Propagation in arithmetic and comparison operations | ||
--------------------------------------------------- | ||
|
@@ -945,3 +946,25 @@ work with ``NA``, and generally return ``NA``: | |
in the future. | ||
|
||
See :ref:`dsintro.numpy_interop` for more on ufuncs. | ||
|
||
.. _missing_data.NA.Conversion: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. version added tag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback this is a subsection of the whole |
||
|
||
Conversion | ||
Dr-Irv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
---------- | ||
|
||
If you have a DataFrame or Series using traditional types that have missing data | ||
represented using ``np.nan``, there are convenience methods | ||
:meth:`~Series.as_nullable_dtypes` in Series and :meth:`~DataFrame.as_nullable_dtypes` | ||
in DataFrame that can convert data to use the newer dtypes for integers, strings and | ||
booleans listed :ref:`here <basics.dtypes>`. This is especially helpful after reading | ||
in data sets when letting the readers infer default dtypes. | ||
|
||
In this example, while the dtypes of all columns are changed, we show the results for | ||
the first 10 columns. | ||
|
||
.. ipython:: python | ||
|
||
bb = pd.read_csv('data/baseball.csv', index_col='id') | ||
bb[bb.columns[:10]].dtypes | ||
bbn = bb.as_nullable_dtypes() | ||
bbn[bbn.columns[:10]].dtypes |
Uh oh!
There was an error while loading. Please reload this page.