I can't select and filter multiple columns together in Pandas. 'Name'
and 'Year of Rank'
are column names. Thank you!
dw[dw.Name=='El Toro' & dw['Name', 'Year of Rank']]
I can't select and filter multiple columns together in Pandas. 'Name'
and 'Year of Rank'
are column names. Thank you!
dw[dw.Name=='El Toro' & dw['Name', 'Year of Rank']]
I believe this is what you want:
dw[dw['Name'] == 'El Toro'][['Name','Year of Rank']]
or alternatively:
dw.loc[ dw['Name'] == 'El Toro', ['Name','Year of Rank']]
Edit: As pointed out in the comments, the second one is much preferred as it deals with the filtering and selection as a single entity.
import pandas as pd
dw = pd.DataFrame([
{'Name': 'A', 'Year of Rank':1992, 'Rank': 1},
{'Name': 'El Toro', 'Year of Rank':1993, 'Rank': 2},
{'Name': 'C', 'Year of Rank':1994, 'Rank': 3}])
dw[dw.Name == 'El Toro'][['Name', 'Year of Rank']]
Like this?
Next time you try provide more context like a dummy dataframe.