def df_of_positive(positive_temp): date=[]; place=[]; people=[]; time=[]; people_num=[]; delttime=[]; people_total=[]; for i in range(3): filename=qianfu[i] print("今天日期是:",filename) filename = file+'\\'+filename+'.csy'; try: scanning_code = pd.read_csv(filename,encoding='gbk') #7开这一天的数据 except: print(filename,'is not found.') place_temp=(scanning_code['user_id']==positive_temp['人品_ID']) time_positive = scanning_code[place_temp]['create_time'] id_of_been_to = np.array(scanning_code[place_temp]['grid_point_id']) # 去过的所有场所所有ID for j in range(len(id_of_been_to)): grid_temp =id_of_been_to[j] people_temp = scanning_code[scanning_code['grid_point_id']==grid_temp]['user_id'] #找到这一天同一地点的人群 time_temp = scanning_code[scanning_code['grid_point_id']==grid_temp]['create_time'] index_delt_less_than_30min=[] delt_=[]; for k in range(len(time_temp)): delt= delt_time(time_positive.iloc[j])-delt_time(time_temp.iloc[k]) #计算时间差 if np.abs(delt)<=30: index_delt_less_than_30min.append(k) delt_.append(time_temp.iloc[k].split(" ")[1]) df_temp=(scanning_code[scanning_code['grid_point_id']==grid_temp]).iloc[index_delt_less_than_30min] people_num.append(len(df_temp)) people.append(list(df_temp['user_id'])) place.append(grid_temp) date.append(qianfu[i]) delttime.append(delt_) time.append(time_positive.iloc[j].split(" ")[l]) people_total.append(len(people_temp)) df = pd.DataFrame({'日期':date,'阳者经过时间':time,'地点':place,'经过总人数':people_total,'密接者':people,'密接者时间':delttime,'密接人数':people_num}) return df
时间: 2023-06-09 08:08:30 浏览: 104
日期时间差计算
3星 · 编辑精心推荐
这段代码定义了一个函数,函数名为df_of_positive,它需要一个叫做positive_temp的输入参数。函数内部有一些变量,包括date、place、people、time、people_num、delttime和people_total。在函数中,使用一个for循环来读取三个不同的文件,文件名存储在一个叫做qianfu的列表中。每个文件名都会被加上一些其他的字符串,以便构造完整的文件路径和文件名。然后它会尝试读取这些文件,假设它们以GBK编码,使用pandas的read_csv函数来做到这一点。
阅读全文