How to filter pandas dataframe columns by partial label

gc5

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

behzad.nouri

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to show all of columns name on pandas dataframe?

From Java

How to filter Pandas dataframe using 'in' and 'not in' like in SQL

From Java

How to GroupBy a Dataframe in Pandas and keep Columns

From Dev

Search for String in all Pandas DataFrame columns and filter

From Dev

pandas DataFrame filter by rows and columns

From Dev

How to select DataFrame columns based on partial matching?

From Dev

pandas, how to filter dataframe by column value

From Dev

How to filter pandas dataframe on multiple columns based on a dictionary?

From Dev

How to filter a dataframe by multiple columns?

From Dev

Filter pandas dataframe based on values in multiple columns

From Dev

Pandas filter columns of a DataFrame with bool

From Dev

How to concat Pandas dataframe columns

From Dev

Fastest way to filter a pandas dataframe on multiple columns

From Dev

how to add columns label on a Pandas DataFrame

From Dev

how to split 'number' to separate columns in pandas DataFrame

From Dev

How to efficiently partial argsort Pandas dataframe across columns

From Dev

Filter Pandas dataframe based on combination of two columns

From Dev

How to reduce columns in dataframe pandas

From Dev

Filter a pandas dataframe based on two columns

From Dev

How do you filter rows in a pandas dataframe conditional on columns existing?

From Dev

Python/Pandas: filter and organize the rows and columns of a dataframe based on another dataframe

From Dev

How to filter all dataframe columns to an condition in Pyspark?

From Dev

How to filter pandas dataframe on different conditions

From Dev

Fastest way to filter a pandas dataframe on multiple columns

From Dev

How to filter Pandas rows by another Dataframe columns?

From Dev

How to filter a pandas dataframe by dict column?

From Dev

How to group columns by label in a histogram using a panda DataFrame?

From Dev

Filter dataframe by two columns in Pandas

From Dev

How to Label encode multiple non-contiguous dataframe columns

Related Related

  1. 1

    How to show all of columns name on pandas dataframe?

  2. 2

    How to filter Pandas dataframe using 'in' and 'not in' like in SQL

  3. 3

    How to GroupBy a Dataframe in Pandas and keep Columns

  4. 4

    Search for String in all Pandas DataFrame columns and filter

  5. 5

    pandas DataFrame filter by rows and columns

  6. 6

    How to select DataFrame columns based on partial matching?

  7. 7

    pandas, how to filter dataframe by column value

  8. 8

    How to filter pandas dataframe on multiple columns based on a dictionary?

  9. 9

    How to filter a dataframe by multiple columns?

  10. 10

    Filter pandas dataframe based on values in multiple columns

  11. 11

    Pandas filter columns of a DataFrame with bool

  12. 12

    How to concat Pandas dataframe columns

  13. 13

    Fastest way to filter a pandas dataframe on multiple columns

  14. 14

    how to add columns label on a Pandas DataFrame

  15. 15

    how to split 'number' to separate columns in pandas DataFrame

  16. 16

    How to efficiently partial argsort Pandas dataframe across columns

  17. 17

    Filter Pandas dataframe based on combination of two columns

  18. 18

    How to reduce columns in dataframe pandas

  19. 19

    Filter a pandas dataframe based on two columns

  20. 20

    How do you filter rows in a pandas dataframe conditional on columns existing?

  21. 21

    Python/Pandas: filter and organize the rows and columns of a dataframe based on another dataframe

  22. 22

    How to filter all dataframe columns to an condition in Pyspark?

  23. 23

    How to filter pandas dataframe on different conditions

  24. 24

    Fastest way to filter a pandas dataframe on multiple columns

  25. 25

    How to filter Pandas rows by another Dataframe columns?

  26. 26

    How to filter a pandas dataframe by dict column?

  27. 27

    How to group columns by label in a histogram using a panda DataFrame?

  28. 28

    Filter dataframe by two columns in Pandas

  29. 29

    How to Label encode multiple non-contiguous dataframe columns

HotTag

Archive