Group by column-specific values in a Dataframe

Asked

Viewed 38 times

1

I have the following dataset:

    Brand   Condition   Fuel    
0   Toyota  Used    Diesel  
1   Suzuki  Used    Petrol  
2   Suzuki  Used    CNG 
3   Suzuki  Used    Petrol  
4   Toyota  Used    Petrol  

It’s over 10,000 records and has over 15 brands. As I filter, for example, only the lines with Brand equal to Toyota?

I tried the following:

df1 = df.filter(items=['Brand','Fuel'], axis=1)
teste = df1.filter(like='Toyota', axis=0)
teste.head()

But he didn’t return anything.

  • 1

    See if that’s not what you want to do result = df[ df['Brand'] == 'Toyota' ]

  • 1

    Exactly that. Thank you, I was thinking the hardest way possible.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.