Python 从 Excel 筛选

Python filter from Excel

我正在努力为 Excel 创建一个 python 自动化程序。

我想根据中位数来划分经度

我要获取的数据是:

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'

下面是我的代码:

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))

下面是这段代码的输出。 output

上面的输出显示了美国的所有经度。 但是,我只想过滤 1.从所有经度中过滤中值, 2. 如果中位数 > 经度: 将经度分配给 'A' 别的: 将经度分配给 'B'

谁能帮我解决这个问题?

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))