1

I have a program that works perfectly in placing orders for my company for a list that I define. I want to know how I could pull the list from an excel file instead of manually typing them out each time?

code below:

Order_List = ['0043777770','003897270','0048377270']

for eachId in Order_List:
#go to website
#find and select item
# enter quantiy
#check out
#save invoice

But instead of me manually entering each order# into the order_list can I pull it from an excel file or read through each order # in the excel? the excel file looks something like this and I need the first column data A2-A20 etc.

enter image description here

1
  • Have you tried reading the excel file into pandas? Commented Apr 16, 2022 at 17:54

2 Answers 2

3

If you want, you can also read only the first column with pd.read_excel. I think this might be a bit more efficient than reading the whole file.

As I see it, you don't want repeated orders, that's why you can use set()

import pandas as pd

df = pd.read_excel("file.xlsx", index_col=None, na_values=['NA'], usecols="A")
# get the first column of df
Order_List  = set(df.iloc[:, 0])

print(Order_List)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use pandas.

With for.

Example.

import pandas as pd

df = pd.read_excel('namexlsx.xlsx')
List_order = []
for i in namexlsx.index:
   order = df.at[i, 'Order number']
   List_order.append(order)

1 Comment

There is really no need to loop through df, it is not very efficient. If you really need a list, the df has a method for that, namely df['Order number'].tolist().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.