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

问题描述 投票:0回答:1

我有一个低于值的数据框

每天有四班

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中创建一个新的数据框,如下所示:shift =在时间上的时间工作(min)的移动总和中的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
python dataframe data-visualization
1个回答
0
投票
>>>import pandas as pd

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

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

要最终显示输出数据框:

>>>print(Dframe)
© www.soinside.com 2019 - 2024. All rights reserved.