Update a DataFrame/Series with the values of another
Project description
# Update a DataFrame/Series with the values of another.
from a_pandas_ex_df_updater import pd_add_df_updater
df1 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
columns=['a', 'b', 'c'])
df2 = pd.DataFrame(np.array([[11, 2, 3], [4, 55, 6], [7, 8, 9], [17, 2, 93]]),
columns=['a', 'x', 'y'])
df3=df1.ds_update(forupdate=df2,update_existing_values=True, add_new_columns=False,add_new_rows=False)
df1
a b c
0 1 2 3
1 4 5 6
2 7 8 9
df2
a x y
0 11 2 3
1 4 55 6
2 7 8 9
3 17 2 93
df3
a b c
0 11 2 3
1 4 5 6
2 7 8 9
df3=df1.ds_update(forupdate=df2,update_existing_values=True, add_new_columns=True,add_new_rows=False)
df1
a b c
0 1 2 3
1 4 5 6
2 7 8 9
df2
a x y
0 11 2 3
1 4 55 6
2 7 8 9
3 17 2 93
df3
a b c x y
0 11 2 3 2 3
1 4 5 6 55 6
2 7 8 9 8 9
df3=df1.ds_update(forupdate=df2,update_existing_values=True, add_new_columns=True,add_new_rows=True)
df1
a b c
0 1 2 3
1 4 5 6
2 7 8 9
df2
a x y
0 11 2 3
1 4 55 6
2 7 8 9
3 17 2 93
df3
a b c x y
0 11 2.0 3.0 2 3
1 4 5.0 6.0 55 6
2 7 8.0 9.0 8 9
3 17 NaN NaN 2 93
df1.ds_update(forupdate=df2,update_existing_values=False, add_new_columns=True,add_new_rows=True)
df1
a b c
0 1 2 3
1 4 5 6
2 7 8 9
df2
a x y
0 11 2 3
1 4 55 6
2 7 8 9
3 17 2 93
df3
a b c x y
0 1 2.0 3.0 2 3
1 4 5.0 6.0 55 6
2 7 8.0 9.0 8 9
3 17 NaN NaN 2 93
Parameters:
df: Union[pd.Series, pd.DataFrame]
forupdate: Union[pd.Series, pd.DataFrame]
update_existing_values:bool
(default=True)
add_new_columns=True
(default=True)
add_new_rows=True
(default=True)
Returns:
Union[pd.Series, pd.DataFrame]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for a_pandas_ex_df_updater-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7f7d57a9649cad4e044285cc5adb93a12caf67a7a1a19a67be066c1d29f4975 |
|
MD5 | 0762dcef7b945c43e483405f6ba7db6a |
|
BLAKE2b-256 | 472e30882831d5aad4fc6f899a33942d1fd024a329469db290e74e02af74eccc |
Close
Hashes for a_pandas_ex_df_updater-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e400cc1e5528d8030afa9e1df88a2730eb5572de1dbf2ea902f5f5573676d237 |
|
MD5 | 08d6625ec1d821700d27b98bbca3c27e |
|
BLAKE2b-256 | dcb1af1e09b0d19619584c99579793970ac6d88ea707db9eb18420976d9a21dd |