Code python

Union two pandas DataFrame

Kontext Kontext visibility 38 comment 0 access_time 2 months ago language English

descriptionCode description

This code snippet shows you how to union two pandas DataFrames in python using concat method in pandas namespace.If the schema is different, pandas will autmatically merge it.

Output

  category  value  user
0        A      0   2.0
1        B      1   3.0
2        C      2   2.0
3        D      3   1.0
4        E      4   1.0
0        A      0   NaN
1        B      1   NaN
2        C      2   NaN
3        D      3   NaN
4        E      4   NaN

For the second DataFrame, column user doesn't exist. Pandas uses  NaN to mark it.

fork_rightFork
more_vert
copyright This page is subject to Site terms.
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts