Skip to main content

Update a DataFrame/Series with the values of another

Project description

pip install a-pandas-ex-df-updater
#    Update a DataFrame/Series with the values of another.

    from a_pandas_ex_df_updater import pd_add_df_updater

    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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

a_pandas_ex_df_updater-0.11.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

a_pandas_ex_df_updater-0.11-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page