2

I have two columns, one has the year, and another has the month data, and I am trying to make one column from them (containing year and month).
Example:

click_year  
-----------
2016     

click_month   
-----------
11

I want to have

YearMonth 
-----------
201611

I tried

date['YearMonth'] = pd.concat((date.click_year, date.click_month)) 

but it gave me "cannot reindex from a duplicate axis" error.

cezar
  • 11,616
  • 6
  • 48
  • 84
Ali
  • 21
  • 2
  • 1
    Welcome to Stack Overflow! You can [take the tour](http://stackoverflow.com/tour) first and learn [How to Ask a good question](http://stackoverflow.com/help/how-to-ask) and create a [Minimal, Complete, and Verifiable](http://stackoverflow.com/help/mcve) example. That makes it easier for us to help you. – Stephen Rauch Mar 25 '17 at 20:59

1 Answers1

-1

Bill's answer on the post might be what you are looking for.

import pandas as pd
df = pd.DataFrame({'click_year': ['2014', '2015'], 'click_month': ['10', '11']})

>>> df
click_month click_year
0          10       2014
1          11       2015

df['YearMonth'] = df[['click_year','click_month']].apply(lambda x : '{}{}'.format(x[0],x[1]), axis=1)

>>> df
  click_month click_year YearMonth
0          10       2014    201410
1          11       2015    201511
Community
  • 1
  • 1
Rohan
  • 5,121
  • 1
  • 17
  • 19