如何在Orange中从RowInstance读取元属性?
Great question! The values() method on Orange.data.table.RowInstance only returns feature values—metadata is stored separately in the metas attribute of the row. Let's break down how to access it properly:
Basic Metadata Value Access
You can iterate over metadata values directly using line.metas, just like you did with values(). Each entry in line.metas is a metadata cell, and you can extract its value with .value (same as you did for feature cells):
# type(line) is Orange.data.table.RowInstance # Print feature values (your original code) print("Feature Values:") for i, cell in enumerate(line.values()): print(cell.value) # Print metadata values print("\nMetadata Values:") for i, meta_cell in enumerate(line.metas): print(meta_cell.value)
Access Metadata with Variable Names
If you want to pair metadata values with their corresponding variable names (instead of just raw values), you can use the row's domain object. The domain's metas list contains definitions for all metadata variables, so you can zip them together with the row's metadata cells:
# Get the domain from the row's associated data table domain = line.domain print("Metadata with Names:") for meta_var, meta_cell in zip(domain.metas, line.metas): print(f"{meta_var.name}: {meta_cell.value}")
This way you'll get clear, labeled metadata values instead of just a list of unlabeled entries.
内容的提问来源于stack exchange,提问作者h3xStream

