本文介绍: 将一列数据按特定行列进行复制,形成DataFrame格式

将一列日期list_date转为 factor2 的同样的行列格式

具体步骤

# 第一步,将模板dataframe进行转置,并和list进行index对齐

list_date = pd.read_pickle(raw_data_path + ‘listdate.pkl’)

factor2_reverse = factor2.T

df_merged = factor2_reverse.merge(list_date, how=’left‘, left_index=True, right_index=True)

df_listdate = df_merged.loc[:, ‘s_info_listdate’]

df_listdate = pd.to_datetime(df_listdate)

#第二步: 扩展数组形状

copydata = list(factor2_reverse.columns)

copydata1 = np.expand_dims(copydata, axis = 0) # 扩展数组形状

#第三步,进行数组的复制

copydata2 = np.repeat(copydata1, factor2_reverse.shape[0], axis = 0)

 

#第四步:转为dataframe既定的格式

copydata3 = pd.DataFrame(copydata2)

copydata3.index = factor2_reverse.index

copydata3.columns = factor2_reverse.columns

 

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注