简体   繁体   English

在数据中寻找模式并对其进行结构化

[英]Finding pattern in data and structuring it

I've a sheet where I paste data from the website, when I paste, it look like this in sheet(Page 1 and Page 2):-我有一张从网站粘贴数据的表格,当我粘贴时,表格中的数据如下所示(第 1 页和第 2 页):-

Here Color Code cells represent the data of one plot, like address , price , area and in address there is pincode这里颜色代码单元格代表一个图的数据,如地址价格面积,地址中有密码

在此处输入图像描述

在此处输入图像描述

I am trying to make it structured like this if you take first two column block in P 1 in above image, I hope now it make some sense:-如果您在上图中的P 1中取前两列块,我正在尝试使其结构像这样,我希望现在它有意义:-

  • I need to grab the Pincode from address我需要从地址中获取 Pincode

  • Address can be anywhere in columns, and below them will be there selling/renting details, like price, area etc地址可以在列中的任何位置,在它们下方将有销售/租赁详细信息,如价格、区域等

在此处输入图像描述

Don't know how to start, column has multiple property data which I want to structure不知道如何开始,列有多个我要构建的属性数据

Here is the sheet link:- https://docs.google.com/spreadsheets/d/1M9YUR2NEc0IUvpwmzw1diMSMG9ukZw-269Rvg531WqY/edit#gid=0这是工作表链接:- https://docs.google.com/spreadsheets/d/1M9YUR2NEc0IUvpwmzw1diMSMG9ukZw-269Rvg531WqY/edit#gid=0

Any suggestions?有什么建议么?

Based on a fixed order of the data, starting at the address after that the price and after that the area基于数据的固定顺序,从地址开始,然后是价格,然后是区域

Delete unrelated data to avoid bugs删除不相关的数据以避免错误

function findPatterns() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const ssname = ss.getSheetByName('Sheet1')
// ranges to process
  let columns = ['A24:A87', 'B24:B267', 'C24:C174']
  let res = []
  let arr = []
  columns.forEach(column => {
    let range = ssname.getRange(column).getValues().flat().filter(r => r)
    range.forEach(e => {
      let addres = e.match(/, CO \d/)
      let price = e.match(/^\$\d+(,\d+)?/gm)
      let area = e.match(/sqft|acres/)
      if (addres != null) {
        let pincode = e.match(/, CO (\d+)/).pop()
        arr.push(e, pincode)
      }
      if (price != null) {
        arr.push(e)
      }
      if (area != null) {
        arr.push(area[0])
        let num = e.match(/\d+(\.\d+)?/)
        if (num != null) {
          arr.push(num[0])
        } else {
          arr.push('')
        }
        res.push(arr)
        arr = []
      }
    })
  })
  res.forEach((el, idx) => {
    range = ssname.getRange('H' + (idx + 2) + ':L' + (idx + 2))
    range.setValues([el])
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM