2

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

tushariyer
  • 906
  • 1
  • 10
  • 20
  • 2
    Possible duplicate of [Pandas - Split dataframe into multiple dataframes based on dates?](https://stackoverflow.com/questions/35907421/pandas-split-dataframe-into-multiple-dataframes-based-on-dates) – Thomas Dussaut Jul 17 '17 at 13:00

1 Answers1

2

Let's use boolean indexing:

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

df_weekend = df_original[mask]
df_weekday = df_original[~mask]
Scott Boston
  • 147,308
  • 15
  • 139
  • 187
  • When I try that I get the error `raise ValueError('Must pass DataFrame with boolean values only') ValueError: Must pass DataFrame with boolean values only` – tushariyer Jul 17 '17 at 13:08