Reputation: 7
I have the following list:
mylist = [5093, 5243, 5390, 5753, 5818, 5961, ...]
How to know if the value of a column == elements of mylist and print in mylist elements order:
import openpyxl
doc = openpyxl.load_workbook("file.xlsx")
hoj = doc['Hoj']
for fil in hoj.rows:
for column in fil:
if column.value == ELEMENT IN "mylist":
print(column.value) --> I NEED THAT ORDERED BY MYLIST
sorry for my bad english
Upvotes: 0
Views: 32
Reputation: 739
It would be easy if you use pandas so, after that just use boolean masking:
import pandas as pd
df = pd.read_excel('datafile.xlsx') #dataframe
for elt in my_list: #my_list is the list want to evaluate
print(df[df[column] == elt]) #boolean masking. Column is the column you want to evaluate
Upvotes: 2