随着时间的推移,一个人或“工人”可以有多个职位分配(工作)。每个职位分配都有一个validfrom和valid to date。我想在每个月16号获得一个工人的全日制同等待遇。你知道吗
数据帧df3包含一个人员列表 数据帧df4包含位置列表 df3.RecId_x等于df4.Worker,应用于在两个数据帧之间建立链接。你知道吗
df3.columns
Out[81]: Index(['PersonnelNumber', 'Person', 'RecId_x', 'NameAlias'], dtype='object')
df4.columns
Out[82]:
Index(['Worker', 'Position', 'ValidFrom_ass', 'ValidTo_ass', 'Description',
'FullTimeEquivalency', 'Department'],
dtype='object')
示例:
df3.head(2)
Out[84]:
PersonnelNumber Person RecId_x NameAlias
0 2 5637162883 5637144780 Mr A
1 6 5637162893 5637144784 Mr B
df4[df4['Worker']==5637144780]
Out[86]:
Worker Position ValidFrom_ass ValidTo_ass \
793 5637144780 5637158077 2017-01-01 01:00:00 2017-02-20 00:59:59
875 5637144780 5637158076 2017-02-21 01:00:00 2020-01-10 00:59:59
Description FullTimeEquivalency Department
793 Position1 1.0 5637336774
875 Position2 0.9 5637336774
目标:
我的目标是在df3列中添加“jan\u fte”、“feb\u fte”,。。。 列出每个员工当月的fte。你知道吗
我的尝试:
df3['Jan_fte']= df4[(df4['Worker']==df3.RecId_x) & (df4['ValidFrom_ass'] <= '2017-01-16') & (df4['ValidTo_ass'] >='2017-01-16')]
ValueError: Can only compare identically-labeled Series objects
df3型 姓名别名,一月,二月,三月。。你知道吗
先生,1.0,1.0,0.9,。。你知道吗
由于A先生于2017年1月16日被分配到职位1,全职员工的全职员工比例为1.0,因此1月的全职员工比例为1.0 由于A先生于2017年2月16日被分配到职位1,2月fte为1.0,全职同等职位为1.0 3月fte为0.9,因为A先生于2017年3月16日被分配到2号职位,全职员工为0.9
复制数据:
import pandas as pd
#df3 dict as df8
df8 = pd.DataFrame({'NameAlias': {0: 'Mr A', 1: 'Mr B'},
'Person': {0: 5637162883, 1: 5637162893},
'PersonnelNumber': {0: '2', 1: '6'},
'RecId_x': {0: 5637144780, 1: 5637144784}})
#df4 filtered on worker 5637144780 dict as df9:
df9 = pd.DataFrame({'Department': {793: 5637336774, 875: 5637336774},
'Description': {793: 'Position 1', 875: 'Position 2'},
'FullTimeEquivalency': {793: 1.0, 875: 0.90000000000000002},
'Position': {793: 5637158077, 875: 5637158076},
'ValidFrom_ass': {793: pd.Timestamp('2017-01-01 01:00:00'),
875: pd.Timestamp('2017-02-21 01:00:00')},
'ValidTo_ass': {793: pd.Timestamp('2017-02-20 00:59:59'),
875: pd.Timestamp('2020-01-10 00:59:59')},
'Worker': {793: 5637144780, 875: 5637144780}})
我找到了一个达到预期效果的方法。你知道吗
相关问题 更多 >
编程相关推荐