Combining 2 data series into one

Bhaskar Dhariyal dhariyalbhaskar at gmail.com
Wed Jun 28 07:19:20 EDT 2017


On Wednesday, 28 June 2017 14:43:48 UTC+5:30, Paul Barry  wrote:
> This should do it:
> 
> >>> import pandas as pd
> >>>
> >>> df1 = pd.DataFrame(['bhaskar', 'Rohit'], columns=['first_name'])
> >>> df1
>   first_name
> 0    bhaskar
> 1      Rohit
> >>> df2 = pd.DataFrame(['dhariyal', 'Gavval'], columns=['last_name'])
> >>> df2
>   last_name
> 0  dhariyal
> 1    Gavval
> >>> df = pd.DataFrame()
> >>> df['name'] = df1['first_name'] + ' ' + df2['last_name']
> >>> df
>                name
> 0  bhaskar dhariyal
> 1      Rohit Gavval
> >>>
> 
> Again, I draw your attention to Jake VanderPlas's excellent book, which is
> available for free on the web.  All of these kind of data manipulations are
> covered there:  https://github.com/jakevdp/PythonDataScienceHandbook - the
> hard copy is worth owning too (if you plan to do a lot of work using
> numpy/pandas).
> 
> I'd also recommend the upcoming 2nd edition of Wes McKinney's "Python for
> Data Analysis" book - I've just finished tech reviewing it for O'Reilly,
> and it is very good, too - highly recommended.
> 
> Regards.
> 
> Paul.
> 
> On 28 June 2017 at 07:11, Bhaskar Dhariyal <dhariyalbhaskar at gmail.com>
> wrote:
> 
> > Hi!
> >
> > I have 2 dataframe i.e. df1['first_name'] and df2['last_name']. I want to
> > make it as df['name']. How to do it using pandas dataframe.
> >
> > first_name
> > ----------
> > bhaskar
> > Rohit
> >
> >
> > last_name
> > -----------
> > dhariyal
> > Gavval
> >
> > should appear as
> >
> > name
> > ----------
> > bhaskar dhariyal
> > Rohit Gavval
> >
> >
> >
> > Thanks
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> 
> 
> 
> -- 
> Paul Barry, t: @barrypj <https://twitter.com/barrypj> - w:
> http://paulbarry.itcarlow.ie - e: paul.barry at itcarlow.ie
> Lecturer, Computer Networking: Institute of Technology, Carlow, Ireland.

https://drive.google.com/open?id=0Bw2Avni0DUa3aFJKdC1Xd2trM2c
link to code



More information about the Python-list mailing list