I have a dataframe,df
Index eventName Count pct
2017-08-09 ABC 24 95.00%
2017-08-09 CDE 140 98.50%
2017-08-
You can use:
df.rename(columns={'Index': 'New_name'}, inplace=True)
df['New_name'] = pd.to_datetime(df['New_name'])
df['Day_df'] = df['New_name'].dt.weekday_name
df.groupby(['Day_df']).count()
By using value_counts
df.Index=pd.to_datetime(df.Index)
df.Index.dt.weekday_name.value_counts()
Out[994]:
Wednesday 3
Thursday 2
Friday 2
Name: Index, dtype: int64
Wen's answer with value_counts
is good, but does not account for the possibility of NaN
s in the pct
column.
Assuming Index
is the index, you can call groupby
+ count
-
df.index = pd.to_datetime(df.index)
df.groupby(df.index.weekday_name).pct.count()
Index
Friday 2
Thursday 2
Wednesday 3
Name: pct, dtype: int64
To sort on weekday, convert to pd.Categorical
, as shown here.