1 回答

TA贡献1877条经验 获得超1个赞
假设您只想要天数:
num_days = df['day'].value_counts()
如果您想要数据集中的天数百分比。
df['day'].value_counts(normalize=True)
更进一步,看起来您想要数据集中的天数与可能的天数。
# Create series for days in your dataframe
days_in_df = df['day'].value_counts()
# Create a dataframe with all days
start = '01/01/2019'
end = '01/31/2019'
all_days_df = pd.DataFrame(data={'datetime':pd.date_range(start='01/01/2019',periods=31,freq='d')})
all_days_df['all_days'] = all_days_df['datetime'].dt.day_name()
# Use that for value counts
all_days_count = all_days_df['all_days'].value_counts()
# We now merge them
result = pd.concat([all_days_count,days_in_df],axis=1,sort=True)
# Finnaly we can get the ration
result['day']/result['all_days']
添加回答
举报