python code snippet

codes


import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler


date_start = '2022-10-01'
def times_job(x):
    return 180 / (pd.to_datetime(x) - pd.to_datetime(date_start)).days

# load a csv file as a dataframe
df = pd.read_csv('staff.csv')
# filter rows as job_ranks not null
df = df[df['job_ranks'].notnull()]
print(df)
# create a new column named times
# check if created date greater than 6 months
# if yes, set times to 1, else calculate times of 6 months compared to delta date, set tot to the times of the result
df['times'] = df['created'].apply(lambda x: times_job(x))
# req_tot_jira multiply times
# df['req_tot_jira'] = df['req_tot_jira'] * df['times']
# draw scatter plot with x-axis as job_ranks and y-axis as tot , df1 df2 in difeerent subplot
# label um_name on scatter name
plt.scatter(df['job_ranks'], df['req_tot_jira'])
#  draw a vertical line at job_ranks mean
plt.axvline(df['job_ranks'].mean(), color='k', linestyle='dashed', linewidth=1)
plt.axhline(df['req_tot_jira'].mean(), color='k', linestyle='dashed', linewidth=1)
# print label of job_ranks variance and load variance
plt.text(df['job_ranks'].max()*0.9, df['req_tot_jira'].max(), 'ranks variance: ' + str(df['job_ranks'].var()))
plt.text(df['job_ranks'].max()*0.9, df['req_tot_jira'].max()*0.95, 'load variance: ' + str(df['req_tot_jira'].var()))

# group dataframe team column values
df_group = df.groupby('team_name')
# draw subplots with different team_name as grid of 3
for i, j in enumerate(df_group):
    plt.subplots_adjust(wspace = 0.5, hspace = 1)
    plt.subplot(len(df_group), 3, i+1)
    plt.ylim(0,15)
    plt.scatter(j[1]['job_ranks'], j[1]['req_tot_jira'])
    plt.title(j[0])

# for i, j in enumerate(df_group):
#     plt.subplot(len(df_group), 1, figsize=(10, 10))
plt.show()
# for i in df_group:
#     print(i[1])
# print(df_group)
df['Quadrant'] = df.apply(lambda row: 1 if row['job_ranks'] > x_mean and row['req_tot_jira'] > y_mean else \
                      2 if row['job_ranks'] < x_mean and row['req_tot_jira'] > y_mean else \
                      3 if row['job_ranks'] < x_mean and row['req_tot_jira'] < y_mean else \
                      4 if row['job_ranks'] > x_mean and row['req_tot_jira'] < y_mean else None, axis=1)
counts = df['Quadrant'].value_counts()
quadrant_counts = df['Quadrant'].value_counts()
quadrant_names = sorted(quadrant_counts.index)
quadrant_points = ''
for quadrant in quadrant_names:
    count = quadrant_counts[quadrant]
    quadrant_points = quadrant_points + (f"{quadrant}:{count}, ")
print(quadrant_points)

match = re.search(r"group:\s+‘(.+)’,\s+name:\s+‘(.+)’,\s+version:\s+‘(.+)’", code)
if match:
group = match.group(1)
name = match.group(2)
version = match.group(3)

# 构建新的依赖项格式
new_code = f"compile '{group}:{name}:{version}'"

print("Original Code:", code)
print("Converted Code:", new_code)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值