python:基于现有数据框列创建新数据框(日期)

时间:2017-04-11 14:50:16

标签: python dataframe data-visualization

我的数据框数值低于

每天四班

date        shift  ID timeworked(min)
1/1/2017     1     1   20
1/1/2017     1     9   20
1/1/2017     3     2   100
1/2/2017     2     3   30
1/4/2017     3     4   5
1/1/2017     2     5   9

想要从现有的东西创建新的数据框 NoofId'判断移位=移位中id的计数 班次的工作时间(分钟)总和=该班次工作时间的总和

date       shift      sum of timeworked(min) on the shift  NoofId'sin the shift
1/1/2017     1         40                                  2
1/1/2017     2         9                                   1
1/1/2017     3         100                                 1
1/2/2017     2         30                                  1
1/4/2017     3         5                                   1

1 个答案:

答案 0 :(得分:0)

>>>import pandas as pd

让我们将原始数据框称为Dframe。 现在要向现有Dframe数据框添加列,可以从pandas中使用Serial方法。 让我们也可以使用字符串添加新列:' NoofId'犯罪转移'

>>>Dframe['NoofIds in the shift']=pd.Series([2,1,1,1,1])

最后显示输出数据框:

>>>print(Dframe)
相关问题