N
N
Nikita M.2021-03-07 21:33:33
Python
Nikita M., 2021-03-07 21:33:33

How to parse CSV in a specific order?

There is a goal to parse the CSV database in the following order:
There are three columns: name, phone number, order number. You need to go through the column of phone numbers, and if the number is in a certain list, then you need to take the data of the entire line where this number was.
My implementation:

wishlist = []
df = pandas.read_csv('db.csv', sep=';')
for number in df['phone_numbers']:
    if number in wishlist:
        print(f"{df{'user_name']}, {df['order_id']}, {df['phone_number']}")

but the code does not start parsing all the lines, does not display the number, and also returns to the beginning all the time.
What could be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wispik, 2021-03-07
@Wispik

print(df.loc[df['phone_number'].isin(wishlist)])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question