如何将项目附加到字典中列表的特定索引位置



我有一个名为数据的字典,它看起来像这样:

{'Annou1_date': [NoneType,NoneType,....], 'Appro2_date': [NoneType,NoneType,....], 'Appro3_date': [NoneType,NoneType,....]}

而且,我想更新索引1处的Approv2_date列表,这样我的词典就会显示:

{'Annou1_date': [NoneType,NoneType,....], 'Appro2_date': [NoneType,22nd July 2021,....], 'Appro3_date': [NoneType,NoneType,....]}

我该怎么做?

我试着做:

#RECRUITMENT PRE-PROCESSING SCRIPT
import pandas as pd
import numpy as np
import math
#Reading report file
df1 = pd.read_excel("C:/Users/INT011/Desktop/WorkFlows/Dashboards/Recruitment Workflow/Recruitment Workflow Tasks.xlsx") 
df1 = df1.sort_values(by=["Workflow ID","Task ID"], ascending=True)
wf_id,tk_id,tk_name,sd,ed,delay,st,category,assignee,ini,can_name,can_desig,hod,posi,dept,jb_num,qty,ddj,fdj,lk 
= df1['Workflow ID'].tolist(),df1['Task ID'].tolist(),df1['Task Name'].tolist(),df1['Start Date'].tolist(),df1['End Date'].tolist(),df1['Delay(Days)'].tolist(),df1['Status'].tolist(), 
df1['Category'].tolist(),df1['Assignee Name'].tolist(),df1['Initiator'].tolist(),df1['Name Of Candidate'].tolist(),df1['Candidate Designation'].tolist(),df1['HOD Selection'].tolist(), 
df1['Position'].tolist(),df1['Department'].tolist(),df1['Project Number'].tolist(),df1['Quantity'].tolist(),df1['Desired Date Of Joining'].tolist(),df1['Final Date Of Joining'].tolist(), 
df1['Alfresco Link'].tolist()
sd = pd.to_datetime(df1['Start Date'])
df1['End Date'] = pd.to_datetime(df1['End Date'])
df1['Min Date'] = df1.groupby(['Workflow ID', 'Task Name'])['End Date'].transform('min')
df1['Max Date'] = df1.groupby(['Workflow ID','Task Name'])['End Date'].transform('max')
firstdate = df1['Min Date'].tolist()
lastdate = df1['Max Date'].tolist()
tasklist = np.unique(tk_name)
t = len(tasklist)
task_var_names = [str()]*t
for i in range(t):
task_var_names[i] = tasklist[i][0:5]+str(i+1)+"_date"

#New Columns for Output File
a = len(wf_id)
x=np.array(wf_id)
x=np.unique(wf_id)
b=len(x)
data = dict((task_var_names[i], [None]*b) for i in range(t))
runnintask,status,ct,initiator,HOD,jb,alflink = [str()]*b,[str()]*b,[str()]*b,[str()]*b,[str()]*b,[str()]*b,[str()]*b
for i in range(0,b):
for j in range(0,a):        
if x[i] == wf_id[j]:
alflink[i] = lk[j]
ct[i] = category[j]
for k in range(t):
if tk_name[j] == tasklist[k]:
data[task_var_names[k]] = ed[j]

但它将列表替换为单个值,如:

{'Annou1_date': '17-Jul-2021', 'Appro2_date': '24-Jul-2021', 'Appro3_date': '22-Jul-2021'}
  • 从字典中获取作为listAppro2_date的值
  • 现在按照您所需的索引更新list

lst[index] = new_value

d = {'Annou1_date': [None,None], 'Appro2_date': [None,None,None], 'Appro3_date': [None,None,None]}
date_str = '22nd July 2021'
# Updating the list. Modify data at index - 1
d['Appro2_date'][1] = date_str
print(d)
{'Annou1_date': [None, None], 'Appro2_date': [None, '22nd July 2021', None], 'Appro3_date': [None, None, None]}

相关内容

  • 没有找到相关文章

最新更新