8000 ENH: try to preserve the dtype on combine_first for the case where the two DataFrame objects have the same columns by danielhrisca · Pull Request #39051 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: try to preserve the dtype on combine_first for the case where the two DataFrame objects have the same columns #39051

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

Merged
merged 13 commits into from
Jan 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
further fix and polish the whatsnew entry
  • Loading branch information
danielhrisca committed Jan 13, 2021
commit a2d4e383c6d9b6541bda10f65921b6a9595c94b6
27 changes: 5 additions & 22 deletions doc/source/whatsnew/v1.3.0.rst < F781 span data-view-component="true">
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,27 @@ Preserve dtypes in :meth:`~pandas.DataFrame.combine_first`
.. ipython:: python

df1 = pd.DataFrame({"A": [1, 2, 3], "B": [1, 2, 3]}, index=[0, 1, 2])
df1
df2 = pd.DataFrame({"B": [4, 5, 6], "C": [1, 2, 3]}, index=[2, 3, 4])
df2
combined = df1.combine_first(df2)

*pandas 1.2.x*

.. code-block:: ipython

In [1]: (combined, "---------------", combined.dtypes)
In [1]: combined.dtypes
Out[2]:
( A B C
0 1.0 1.0 NaN
1 2.0 2.0 NaN
2 3.0 3.0 1.0
3 NaN 5.0 2.0
4 NaN 6.0 3.0,
'---------------',
A float64
B float64
C float64
dtype: object)
dtype: object

*pandas 1.3.0*

.. ipython:: python

In [1]: (combined, "---------------", combined.dtypes)
Out[2]:
( A B C
0 1.0 1 NaN
1 2.0 2 NaN
2 3.0 3 1.0
3 NaN 5 2.0
4 NaN 6 3.0,
'---------------',
A float64
B int64
C float64
dtype: object)
combined.dtypes


.. _whatsnew_130.api_breaking.deps:
Expand Down
0