I\'d like to filter out weekend data and only look at data for weekdays (mon(0)-fri(4)). I\'m new to pandas, what\'s the best way to accomplish this in pandas?
your call to the function "weekday" does not work as it operates on the index of data.my_dt, which is an int64 array (this is where the error message comes from)
you could create a new column in data containing the weekdays using something like:
data['weekday'] = data['my_dt'].apply(lambda x: x.weekday())
then you can filter for weekdays with:
weekdays_only = data[data['weekday'] < 5 ]
I hope this helps
Faster way would be to use DatetimeIndex.weekday, like so:
temp = pd.DatetimeIndex(data['my_dt'])
data['weekday'] = temp.weekday
Much much faster, especially for a large number of rows. For further info, check this answer.