tushariyer
tushariyer

Reputation: 958

split pandas dataframe into two based on day of the week

I have a data frame that looks like the image below:

Image

the data frame is called df_original.

How do I split it so that I end up with a df_weekend which contains all the data that occurs on Saturday and Sundar, and df_weekday which contains all the data from Monday to Friday?

I originally tried using the solution found at Pandas - Split dataframe into multiple dataframes based on dates?

But I ran into a ValueError

Upvotes: 2

Views: 878

Answers (1)

Scott Boston
Scott Boston

Reputation: 153500

Let's use boolean indexing:

mask = df_original['day'].isin(['Saturday','Sunday'])

df_weekend = df_original[mask]
df_weekday = df_original[~mask]

Upvotes: 2

Related Questions