Any good explanations on pd.merge(df,df2, on=['Code', 'Region'])

Paul Moore p.f.moore at gmail.com
Wed Nov 8 06:50:31 EST 2017


On 8 November 2017 at 11:15, Karsten Hilbert <Karsten.Hilbert at gmx.net> wrote:
> On Wed, Nov 08, 2017 at 09:26:04AM +0000, David Shi via Python-list wrote:
>
>>  I am trying to gain a clear understanding on pd.merge(df,df2, on=['Code', 'Region']).
>> Can anyone assist?
>
>         ncq at hermes:~$ python
>         Python 2.7.14 (default, Sep 17 2017, 18:50:44)
>         [GCC 7.2.0] on linux2
>         Type "help", "copyright", "credits" or "license" for more information.
>         >>> pd.merge(df,df2, on=['Code', 'Region'])
>         Traceback (most recent call last):
>           File "<stdin>", line 1, in <module>
>         NameError: name 'pd' is not defined
>         >>>
>
> You will need to provide more context to get help.

... but given that I happen to know (mostly by chance) that pd is a
commonly used short form when importing Pandas ("import pandas as pd")
you should probably start with the documentation on merge:
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html

If that isn't sufficient for you, please provide a better explanation
of what you don't understand, what you have tried and how it didn't
match your expectations, and maybe someone on the list who is familiar
with Pandas will be able to assist you.

Paul



More information about the Python-list mailing list