I have a dataframe with a DATE row and I need to convert it to a row of value 1 if the date is a weekend day and 0 if it is not.
So far, I converted the data to weekdays
df['WEEKDAY'] = pandas.to_datetime(df['DATE']).dt.dayofweek
It's there a way to create this "WEEKEND" row without functions?
Thanks!
Use df. dates1-df. dates2 to find the difference between the two dates and then convert the result in the form of months.
Pandas has a built-in function called to_datetime()that converts date and time in string format to a DateTime object. As you can see, the 'date' column in the DataFrame is currently of a string-type object. Thus, to_datetime() converts the column to a series of the appropriate datetime64 dtype.
One more way of getting weekend indicator is by where
function:
df['WEEKDAY'] = np.where((df['DATE']).dt.dayofweek) < 5,0,1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With