[英]How make dataframes with loop row? Pandas
I am trying to get some new dataframes from one by column "day_of_week".我正在尝试从“day_of_week”列中获取一些新的数据框。 Can I automate this process with loop row?
我可以用循环行自动化这个过程吗?
grouped = sleep.groupby('day_of_week')
monday = grouped.get_group(0).loc[:, 'df']
tuesday = grouped.get_group(1).loc[:, 'df']
wednesday = grouped.get_group(2).loc[:, 'df']
Sample of Data:数据样本:
Date Sleep Hours Alimem DoW
8 2020-01-09 4 9.6 0 3
9 2020-01-10 0 4.8 0 4
10 2020-01-11 0 0.0 0 5
11 2020-01-12 0 0.0 0 6
13 2020-01-13 0 7.2 0 0
14 2020-01-14 0 7.2 0 1
15 2020-01-15 0 7.2 0 2
16 2020-01-16 3 7.2 0 3
17 2020-01-17 0 6.4 0 4
18 2020-01-18 0 2.4 0 5
19 2020-01-19 0 2.4 0 6
20 2020-01-20 0 7.2 0 0
21 2020-01-21 0 7.2 0 1
22 2020-01-22 3 7.2 0 2
23 2020-01-23 0 7.2 0 3
24 2020-01-24 0 6.4 0 4
25 2020-01-25 0 3.2 0 5
This is one way to do it这是一种方法
days = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
grouped = sleep.groupby('day_of_week')
groups = {days[i]: grouped.get_group(i).loc[:, 'df'] for i in range(len(days))}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.