r/pythonhelp • • Dec 08 '22

Can't Understand What is Wrong In My Looping Code

I have created an excel sheet and gives headings like [ Item_1 , Item_2 ] parallel to each other & store data in those headings . #using this stored data in other application.

What I want is :-

If Item_1 (Cell contains value):

do this (specific steps)

Else(if Cell is empty) :

do this(specific steps)

SAME GOES FOR [ ITEM_2 ]

In loop

I am Able to Successfully Loop [ Item_1 ] only

2nd Item is not looping (getting no error in code it's working ok but not reading 2nd item)

To check Cell Values(empty or not) I am Using Below Code :-

if pd.isna(df.loc[0, 'Item_1']) is False:

Full Code Demo

df = pd.read_excel(r"excel file link .xlsx)

itm1 = df["Item_1"].values

itm2 = df["Item_2"].values

zipped = zip(itm1, itm2)

for (a, b) in zipped:

if pd.isna(df.loc[0, 'Item_1']) is False:

do this

else :

do this

it's looping item_1 only not including item_2 .

0 Upvotes

3 comments sorted by

2

u/Goobyalus Dec 08 '22

Please edit to format this code properly for Reddit

1

u/raja0008 Dec 10 '22

What happened you didn't reply?