Suppose the following dataframe:
import pandas as pd
data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'],
'Height of Person': [5.1, 6.2, 5.1, 5.2],
'Qualification': ['Msc', 'MA', 'Msc', 'Msc'],
'Country is': ['US', 'UK', 'GE', 'ET']
}
df = pd.DataFrame(data)
display(df)
I would like to specify columns that should remain in the dataframe based on a number of strings that are present in the index.
E.g. Keep those columns whose index contain "Name" or "Country" should result in:
data2 = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'],
'Country is': ['US', 'UK', 'GE', 'ET']
}
df2 = pd.DataFrame(data2)
display(df2)
I tried using
df = df.filter(like=["Name"])
but I am not sure how to apply multiple expressions (strings) at once.