Home > OS >  seach a barcode trough the excel file and add number in front of each barcode to count them by pytho
seach a barcode trough the excel file and add number in front of each barcode to count them by pytho

Time:04-30

i wanna count Goods inside a warehouse by reading their barcodes using a handheld barcode scanner i can read barcodes simply by using this code :

a = input()

i have an excel file (*.xlsx file) with all the barcode of goods like this :

excel file screenshot

As you can see, i have to search all A1 to A(n) (all rows in column [A] which is more than 4000 rows in origin file) find the barcode address and add a number in corresponding cell front of it in cells B1 to B(n)

for example if i scan the barcode >>> 1142036176 search that number in A1 to A(n) rows and it will find it in cell A2, so for counting it, B2 is blank cell so, Because this cell is empty, it must write the number 1 in its corresponding cell, but if i scan 1128059339 , it,s in A1 and it's corresponding counted number is in B1 that is 9 and it must turns to the 10

i haven,t any clue about how to do it and don,t know the syntax of commands for this purpose can you give me a simple code that do the task? thanks

CodePudding user response:

This would work for you:

import pandas as pd
df=pd.read_excel('sam2.xlsx',header=None)
n=input()
df[1]=df[1].fillna(0)
df.loc[df[0]==int(n),1] =1
df.to_excel('sam2.xlsx',index=False,header=False)

Do comment if you face any error.
Here you need to pip install openpyxl to work with excel.

If you want to edit corresponding G column just change the index of column.

import pandas as pd
df=pd.read_excel('sam2.xlsx',header=None)
n=input()
df[6]=df[6].fillna(0)
df.loc[df[0]==int(n),6] =1
df.to_excel('sam2.xlsx',index=False,header=False)

This should solve your current problem.

  • Related