from datetime import datetime
def zodiac_sign(input):
try:
date = datetime.strptime(input, '%Y-%m-%d')
if date.month == 12:
astro_sign = 'Sagittarius' if (date.day < 22) else 'Capricorn'
elif date.month == 1:
astro_sign = 'Capricorn' if (date.day < 20) else 'Aquarius'
elif date.month == 2:
astro_sign = 'Aquarius' if (date.day < 19) else 'Pisces'
elif date.month == 3:
astro_sign = 'Pisces' if (date.day < 21) else 'Aries'
elif date.month == 4:
astro_sign = 'Aries' if (date.day < 20) else 'Taurus'
elif date.month == 5:
astro_sign = 'Taurus' if (date.day < 21) else 'Gemini'
elif date.month == 6:
astro_sign = 'Gemini' if (date.day < 21) else 'Cancer'
elif date.month == 7:
astro_sign = 'Cancer' if (date.day < 23) else 'Leo'
elif date.month == 8:
astro_sign = 'Leo' if (date.day < 23) else 'Virgo'
elif date.month == 9:
astro_sign = 'Virgo' if (date.day < 23) else 'Libra'
elif date.month == 10:
astro_sign = 'Libra' if (date.day < 23) else 'Scorpio'
elif date.month == 11:
astro_sign = 'Scorpio' if (date.day < 22) else 'Sagittarius'
except:
astro_sign = None
return(astro_sign)
largedf['Astro sign'] = zodiac_sign(largedf['born'])
The above is the code. This is the output I am getting
largedf[['born','Astro sign']]
It works when I do it individually though