Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a CSV file that has data about users. and I want to filter them by name endings. it is an example of my CSV file:

index, name, id, status
1, John, 500, online
2, Anne, 485, offline
3, Angel, 856, online
4, Lusia, 777, offline
from this, I want to get only names that have vowel endings. I expected this result:

index, name, id, status
1, Anne, 485, offline
2, Lusia, 777, offline

that's why I have used python which is in the example:
output is:
index, name, id, status
"2," "Anne," "485," "offline"
"4," "Lusia," "777," "offline"

So problems are:

the numbers are not in the correct order.
as you can see each row has the addition of " " symbol how can I fix this? please give me solutions:)

What I have tried:

import csv
import pandas

df = pandas.read_csv('us.csv')
filtereddf = df[df.name.str[-1].apply(lambda x: x in ['a', 'e', 'i', 'o', 'u','а', 'и', 'е', 'я', 'у', 'о', 'ё', 'A','E', 'I', 'O'])]
filtereddf.to_csv('output_filtered_sample1.csv', index=False, quoting=1)
Posted
Updated 14-Oct-22 22:08pm

1 solution

Python
filtereddf.to_csv('output_filtered_sample1.csv', index=False, quoting=1)

Adding quoting=1 adds quotes to each field. The index numbers are part of each record so will be the same after filtering. If you want different index numbers then you need to set index=True, and omit the numbers from the input records.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900