-1

i have two dataframes

I will use this dataframe to filter that dataframe by the column names.

How can i do that with pandas?

  • 1
    Please do not post pics and please post [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – SomeDude Aug 23 '22 at 20:09
  • Refrain from showing your dataframe as an image. Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Aug 23 '22 at 23:29

1 Answers1

0

If the data frame with the column names all exist(No non-existent value) then you can just turn the column names into a list and put it in like this

df = df[column_list]

Otherwise like this

df.loc[:, df.columns.isin(column_list)`
Thanabhas
  • 49
  • 6