extract() method
Extracts columns from a dataframe to a new dataframe.
Syntax
dataframe_name.extract(columns = ["column"|("column", "new_column_name"), "...n"])
Parameters
Name | Description |
---|---|
columns = ["column" | ("column", "new_column_name"), "...n"] |
The column or columns to extract. The columns are extract in the order that you list them. You can update one or more column names at the same time that you extract the columns. Enclose the existing name and the new name in parentheses. For example: ("ProdDesc", "Product Description") |
Returns
HCL dataframe.
Examples
Extract the specified columns to a new dataframe
You want a reduced set of information for the items in an inventory: basic identifying information, location, and quantity on hand. You extract five relevant columns from the inventory dataframe to the inventory_brief dataframe. You omit all columns that contain information you do not currently need.
inventory_brief = inventory.extract(columns = ["ProdNo", "ProdDesc", "ProdCls", "Location", "QtyOH"])
Extract the specified columns and rename them in a new dataframe
You extract a subset of columns from the inventory dataframe and you rename them in the new dataframe.
inventory_brief = inventory.extract(columns = [("ProdNo", "Prod Number"), ("ProdDesc", "Prod Description"), ("ProdCls", "Prod Class"), "Location", ("QtyOH", "Quantity")])