Given a Pandas data-frame(df) and a list(List1) containing lot of items which may or may not be data-frame column names. is it possible to print only those data-frame columns whose names are present in the given list.
Eg1: data-frame columns names are: 'one', 'two', 'three' List items are : 'one' , 'four', 'two'. Wanted to print only 'one' and 'two' data-frame column
List1=['one', 'four', 'two']
for item in List1:
if item in df.columns:
print(df.item)
Above code throws AttributeError: 'DataFrame' object has no attribute 'item' which is perfectly fine.
I am just trying to print only those data-frame columns whose names are present in the given list, if it is possible. Tried to find the workaround from pandas docs: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.columns.html