0

What I have:

Month|Year
 Jan |2019
 Feb |2019
 Jan |2020
 Feb |2020

What I want is to add another column:

Month|Year|month_yr
 Jan |2019|Jan19
 Feb |2019|Feb19
 Jan |2020|Jan20
 Feb |2020|Feb20

What I tried:

df2['month_yr']=df2.month + df2.year

But this is giving me Jan2019,Jan2020 etc. I do not want the full year but the last 2 digits like Jan19,Jan20 etc

Thank You

2
  • 2
    df2['month_yr']=df2.month + df2.year.str[-2:]? Commented Feb 3, 2020 at 10:56
  • Please post a minimal reproducible example Commented Feb 3, 2020 at 10:56

1 Answer 1

2

try

df2['month_yr']=df2.month + df2['Year'].str[-2:]

this should work

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.