Home > Net >  How to pull excel data into a list to use python?
How to pull excel data into a list to use python?

Time:04-17

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

CodePudding user response:

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)

CodePudding user response:

You can use pandas.

With for.

Example.

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