pandas按照特定顺序输出的实现代码-创新互联
df.groupby() 之后按照特定顺序输出,方便后续作图,或者跟其他df对比作图。
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、网络空间、营销软件、网站建设、江苏网站维护、网站推广。## 构造 pd.DataFrame patient_id = ['71835318256532', '87791375711', '66979212649388', '46569922967175', '998612492555522', '982293214194', '89981833848', '17912315786975', '4683495482494', '1484143378533', '56866972273357', '7796319285658', '414462476158336', '449519578512573', '61826664459895'] week = ['tuesday', 'tuesday', 'wednesday', 'monday', 'tuesday', 'monday', 'friday', 'tuesday', 'monday', 'friday', 'saturday', 'thursday', 'wednesday', 'thursday', 'wednesday'] d = {'patient_id': patient_id, 'week':week} test = pd.DataFrame(data=d) ## 聚类计数 test.groupby('week')['patient_id'].count() ## output week friday 2 monday 3 saturday 1 thursday 2 tuesday 4 wednesday 3 Name: patient_id, dtype: int64 ## 按照特定顺序输出 ind = ['monday','tuesday','wednesday','thursday','friday','saturday'] test.groupby('week')['patient_id'].count()[ind] ## output week monday 3 tuesday 4 wednesday 3 thursday 2 friday 2 saturday 1 Name: patient_id, dtype: int64
新闻名称:pandas按照特定顺序输出的实现代码-创新互联
文章源于:http://scyanting.com/article/csgjic.html