I am trying to filter pandas dataframe columns (with type pandas.core.index.Index
) by a partial label.
I am searching for a builtin method that achieve the same result as:
partial_label = 'partial_lab'
columns = df.columns
columns = [c for c in columns if c.startswith(partial_label)]
df = df[columns]
Is there anything builtin to obtain this?
Thanks
possible solutions:
df.filter(regex='partial_lab.*')
or
idx = df.columns.to_series().str.startswith('partial_lab')
df.loc[:,idx]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments