Explain how to select data from multiple columns based on criteria.

960    Asked by ranjan_6399 in Data Science , Asked on Jan 15, 2020
Answered by Ranjana Admin

For selecting multiple data based on criteria, we have to create a simple dataframe to illustrate the dataset.

import pandas as pd

df = pd.DataFrame({'col1':[1,2,3,4],'col2':[444,555,666,444],'col3':['abc','def','ghi','xyz']})



df.head()

Now we Select from DataFrame using criteria from multiple columns

newdf = df[(df['col1']>2) & (df['col2']==444)]

newdf



Your Answer

Interviews

Parent Categories