'Data Frame with unique pandas

I have a dataFrame(just a column) which has vehicle brands and its models like, Toyota Rav4, Kia Soul, (brand and models at the same column), I want to show all of Volvo's models. Output should be like that,

Volvo xc90
Volvo xc60
Volvo V90
.
.
.

What is the best coding?



Solution 1:[1]

Use str.contains('Volvo'). Demonstration:

df = pd.DataFrame(['Volvo xc90', 'Volvo xc60', 'Volvo V90', 'abc'])
df[df[0].str.contains('Volvo')]

enter image description here

Solution 2:[2]

Try using .str.split:

filtered = df[df['car'].str.split().str[0] == 'Volvo']

Output:

>>> filtered
          car
0  Volvo xc90
2  Volvo xc60
4   Volvo V90

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 keramat
Solution 2 richardec