Filtring csv file datas and save them another csv file using Python

I have a .csv file that has data like that:

index, name, id
1 john 512
2 Anne 895
3 Angel 897
4 Lusia 777

So I want to filter them by name endings and get names only which have vowel endings. And the result must be like that:

index, name,     id
1      Anne     895
2      Lusia    777

After filtering, I want to save the result in another .csv file. I am trying various ways to get the correct result, However, I could not do that. please help me :face_holding_back_tears:

I’m going to presume you’re loading the data ok from the CSV then. Can
you show us the code you have so far? between triple backticks please:

 your code
 goes here

Can you get the names out as strings? row[1] from a CSV row if row
is from the CSV.

Can you write an expression for the last character of that name?

Can you write a string listing the voewls?

Can you write an expression testing whether the last character of the
name is in the vowels?

Cameron Simpson

Any time you’re thinking of operating of CSV files, you should refer to pandas documentation:

import pandas as pd

df = pd.read_csv(...)
df = df.loc[df["name"].str.endswith(("a", "e", "i", "o", "u"))]
1 Like