|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Python+Pandas:
import pandas as pd
import numpy as np
df = pd.read_excel('Sample511.xlsx', usecols='a:g', header=3)
for i in df.index:
df.loc[i, 'nMonths'] = (pd.Timestamp('2024-09-30').to_period('M') - df.loc[i, '入职日期'].to_period('M')).n
df['bonus1'] = pd.cut(df['nMonths'], bins=[1, 12, 36, 60, np.inf], labels=[80, 150, 170, 200], right=False)
df['bonus2'] = pd.cut(df['nMonths'], bins=[1, 12, 36, 60, np.inf], labels=[0, 80, 150, 170], right=False)
for i in df.itertuples():
d = i.入职日期.day
ld = i.离职日期.day if pd.notna(i.离职日期) else 30
if d <= 2:
df.loc[i.Index, '结果'] = i.bonus1
else:
df.loc[i.Index, '结果'] = i.bonus1 * (ld - d + 2) / 30 + i.bonus2 * (d - 2)/30
print(df.iloc[:, [0,1,2,3,10]])
|
|