我已经构建了一个数据框架,它由来自几个相关django模型的数据组成。许多型号都在系统中添加了自己的起始/结束日期。我想将添加的日期与我从系统用户那里获得的日期进行匹配,并为这些日期构建一个字典
我已尝试将数据范围添加到包含与该资源相关的所有信息的数据框中
full_data = pd.DataFrame((resource).values('signum', 'name', 'start',
'end', 'company__name', 'resourcerole__role__name',
'resourcerole__start', 'resourcerole__end',
'resourcecontracttype__contracttype__name',
'resourcecontracttype__start', 'resourcecontracttype__end',
'resourcelocation__site__country', 'resourcelocation__site__city',
'resourcelocation__start', 'resourcelocation__end',
'teamresource__start', 'teamresource__end',
'teamresource__team__name', 'teamresource__team__start',
'teamresource__team__end', 'teamresource__team__productteam__start',
'teamresource__team__productteam__end',
'teamresource__team__productteam__product__name',
'teamresource__team__productteam__product__start',
'teamresource__team__productteam__product__end' ),
columns=['signum', 'name', 'start',
'end', 'company__name', 'resourcerole__role__name',
'resourcerole__start', 'resourcerole__end',
'resourcecontracttype__contracttype__name',
'resourcecontracttype__start', 'resourcecontracttype__end',
'resourcelocation__site__country', 'resourcelocation__site__city',
'resourcelocation__start', 'resourcelocation__end',
'teamresource__start', 'teamresource__end',
'teamresource__team__name', 'teamresource__team__start',
'teamresource__team__end', 'teamresource__team__productteam__start',
'teamresource__team__productteam__end',
'teamresource__team__productteam__product__name',
'teamresource__team__productteam__product__start',
'teamresource__team__productteam__product__end'
])
#Using intersect to match dates
full_data['start'].values[loop_counter] = full_data['start'].values[loop_counter] + relativedelta(months=-1)
if full_data['end'].values[loop_counter] == None:
date_resource = pd.date_range(full_data['start'].values[loop_counter], self.end, freq='MS')
else:
date_resource = pd.date_range(full_data['start'].values[loop_counter], full_data['end'].values[loop_counter], freq='MS')
matched_dates = date_filter.intersection(date_resource)
最终的结果应该是一个数据框架,它包含了关于资源的所有信息以及在我与所有相关模型日期相交后匹配的日期
目前没有回答
相关问题 更多 >
编程相关推荐