[英]Load list with date value into pandas dataframe and plot activity over time
[英]Is there a way to plot/identify a count over time using a list of date ranges?
我有類似於以下的數據,其中顯示成員、他們在哪一天進入設施以及離開設施的日期,看起來類似於以下內容
member_name entry_date exit_date
John 2015-01-01 2020-01-01
Adam 2015-01-01 2019-01-01
Tyler 2016-01-01 2017-01-01
Amy 2017-06-01 2020-01-01
我想知道是否有任何方法可以 A.) 檢索在給定日期有多少成員在設施中的計數(例如,2016 年 6 月 1 日上述樣本中有 3 人)和 B.) 我可以制作一個顯示每天人數的折線圖嗎? 我的實際數據比每天都有人進出設施的數據更復雜,因此我需要能夠識別任何一天而不是月份或年份的設施中的人數。
要獲取 pandas 列(例如日期)上特定值的計數,您可以嘗試:
(df['entry-date'] =='2015-01-01').sum()
對於計數的線圖,您可以執行以下操作:
df.groupby('entry-date')['member_name'].count().plot(kind='line');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.