【问题标题】:Python filter from ExcelExcel 中的 Python 过滤器
【发布时间】:2021-04-22 10:36:57
【问题描述】:

我正在为 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”

谁能帮我解决这个问题?

【问题讨论】:

    标签: python excel filter automation jupyter-notebook


    【解决方案1】:
    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))
    

    【讨论】:

      猜你喜欢
      • 2022-11-21
      • 2017-06-08
      • 2012-12-29
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多