def assemble_col_metadata(full_df, num_col_metadata, num_row_metadata, num_data_cols):
# Extract values
col_metadata_row_inds = range(1, num_col_metadata + 1)
col_metadata_col_inds = range(num_row_metadata + 1, num_row_metadata + num_data_cols + 1)
col_metadata = full_df.iloc[col_metadata_row_inds, col_metadata_col_inds]
# Transpose so that samples are the rows and headers are the columns
col_metadata = col_metadata.T
# Create index from the top row of full_df (after the filler block)
col_metadata.index = full_df.iloc[0, col_metadata_col_inds]
# Create columns from the first column of full_df (before rids start)
col_metadata.columns = full_df.iloc[col_metadata_row_inds, 0]
# Rename the index name and columns name
col_metadata.index.name = column_index_name
col_metadata.columns.name = column_header_name
# Convert metadata to numeric if possible
col_metadata = col_metadata.apply(lambda x: pd.to_numeric(x, errors="ignore"))
return col_metadata
评论列表
文章目录