Skip to content
Advertisement

Python filter from Excel

I am working on to create a python automation program for Excel.

I wanted to divide the longitude based on the median number.

What I want to get data is :

1. get the median number of longitude from excel file,

2. separate longitude based on median number 
   ex) if median number > 91:
          allocate above 91 longitude to 'A'
       else:
          allocate below 91 longitude to 'B'

Below is my code:

for i in range(2, maxRow+1):        
  country = sheet.cell(i,7).value
  longitude = sheet.cell(i,6).value
  median = np.median(longitude)
  if country=="United States":
      print("Unnited States" + str(longitude))

Below is the output from this code. output

above the output is show all longitude in United States. However, I want to filter only 1. filter median from all the longitude, 2. if median > longitude: allocate longitudes to ‘A’ else: allocate longitudes to ‘B’

Could anyone help me with this issue ?

Advertisement

Answer

for i in range(2, maxRow+1):        
country = sheet.cell(i,7).value
longitude = sheet.cell(i,6).value
median = np.median(longitude)
if country=="United States" and int(longitude)>-91:
    print("Unnited States" + str(longitude))
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement