def assemble_row_metadata(full_df, num_col_metadata, num_data_rows, num_row_metadata):
# Extract values
row_metadata_row_inds = range(num_col_metadata + 1, num_col_metadata + num_data_rows + 1)
row_metadata_col_inds = range(1, num_row_metadata + 1)
row_metadata = full_df.iloc[row_metadata_row_inds, row_metadata_col_inds]
# Create index from the first column of full_df (after the filler block)
row_metadata.index = full_df.iloc[row_metadata_row_inds, 0]
# Create columns from the top row of full_df (before cids start)
row_metadata.columns = full_df.iloc[0, row_metadata_col_inds]
# Rename the index name and columns name
row_metadata.index.name = row_index_name
row_metadata.columns.name = row_header_name
# Convert metadata to numeric if possible
row_metadata = row_metadata.apply(lambda x: pd.to_numeric(x, errors="ignore"))
return row_metadata
评论列表
文章目录