Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select only columns of interest dynamically

I am creating a dynamic pandas dataframe from some values. The dataframe dynamically obtains the name of the columns. Each column name has a numeric sequence that concatenates the name:

Name_Column_1, Name_Column_2, etc.

In context, each column name is a category of the data. The data can repeat its category, that’s why I concatenated a number in its name

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Name_1, Email_1, Phono_1, Name_2, Email_2, Phono_2, etc

What I want is to keep only the columns that interest me regardless of their number.
To explain myself, in SQL language it would be something like:

SELECT * FROM TABLE WHERE column_name LIKE ‘Email%’

I’ve been looking for a way to do it, but I can’t find an answer.

Do you recommend any features please?

From already thank you very much.

Regards

>Solution :

IIUC, you can try DataFrame.filter

out = df.filter(like='Email')

If you are interested in the number

out = df.filter(regex='Email_[1-5]')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading