Reputation: 41
I have a DataFrame with a DatetimeIndex and I need to get a new column with values 0 (for a Saturday or Sunday) or 1 (if it was business day) based on the datetime index. How can I do it in a way like:
keytable['var']= if 'Saturday' or 'Sunday' == 0 else return 1
Thanks in advance for the amazing support this community gives to coders worldwide!
Upvotes: 0
Views: 25
Reputation: 150775
You can do:
keytable['var'] = (keytable.index.weekday < 5).astype(int)
Upvotes: 2